将 KILL 与声明的变量一起使用
- 作者: 要上我随便
- 来源: 51数据库
- 2022-10-21
问题描述
我正在尝试使用带有声明变量的 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)
推荐阅读
热点文章
检查拆分键盘
0
带有“上一个"的工具栏和“下一个"用于键盘输入AccessoryView
0
Activity 启动时显示软键盘
0
UIWebView 键盘 - 摆脱“上一个/下一个/完成"酒吧
0
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画
0
我的 iOS 应用程序中的键盘在 iPhone 6 上太高了.如何在 XCode 中调整键盘的分辨率?
0
android:inputType="textEmailAddress";- '@' 键和 '.com' 键?
0
禁用 iPhone 中键盘的方向
0
Android 2.3 模拟器上的印地语键盘问题
0
keyDown 没有被调用
0
