Using KILL with a declared variable(将 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 与声明的变量一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 KILL 与声明的变量一起使用
基础教程推荐
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 在多列上分布任意行 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
