本文介紹了將 KILL 與聲明的變量一起使用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試使用帶有聲明變量的 KILL 語句,但它給了我一個語法錯誤.無論如何不使用常量并以編程方式更改 SPID?
I'm trying to use a KILL statement with a declared variable but it's giving me a syntax error. Is there anyway to not use a constant and programatically change the SPID?
例如:
DECLARE @SPID smallint
SET @SPID = 100
Kill @SPID
順便說一句,這只是一個例子.我需要使用游標在循環中運行 kill 以擺脫舊的持久用戶連接.(別問了)
BTW this is just an example. I need to run the kill in a loop with a cursor to get rid of old persistant user connections. (Don't ask)
推薦答案
我認為您需要為此使用動態 SQL.在使用動態 SQL 執行任何操作之前,請閱讀這個重要頁面.
I think you're going to need dynamic SQL for this. Read this essential page before doing anything with dynamic SQL, please.
DECLARE @SPID smallint
DECLARE @SQL nvarchar(1000)
SET @SPID = 100
SET @SQL = 'KILL ' + CAST(@SPID as varchar(4))
EXEC (@SQL)
這篇關于將 KILL 與聲明的變量一起使用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!