Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用T-SQL在一行中设置多个局部变量?_Sql_Sql Server_Sql Server 2005_Tsql - Fatal编程技术网

如何使用T-SQL在一行中设置多个局部变量?

如何使用T-SQL在一行中设置多个局部变量?,sql,sql-server,sql-server-2005,tsql,Sql,Sql Server,Sql Server 2005,Tsql,我知道可以将它们设置为如下所示: declare @inserted bit declare @removed bit 但是,有没有可能让这更简单,并使用类似于: SELECT @inserted = 0, @removed = 0 DECLARE @inserted BIT, @removed BIT SELECT @inserted = 0, @removed = 0 非常感谢那么: SET @inserted, @removed = 0 在SQL Server 2008及更高版本中

我知道可以将它们设置为如下所示:

declare @inserted bit
declare @removed bit
但是,有没有可能让这更简单,并使用类似于:

SELECT @inserted = 0, @removed = 0
DECLARE @inserted BIT, @removed BIT
SELECT @inserted = 0, @removed = 0
非常感谢

那么:

SET @inserted, @removed = 0
在SQL Server 2008及更高版本中工作(您没有指定SQL Server的哪个版本)

更新:好的,那么您将被困在SQL Server 2005上-在这种情况下,我相信这是您能做的最好的:

declare @inserted BIT = 0, @removed BIT = 0
但是,有没有可能让这更简单,并使用类似于:

SELECT @inserted = 0, @removed = 0
DECLARE @inserted BIT, @removed BIT
SELECT @inserted = 0, @removed = 0
我想你是说

SET @inserted, @removed = 0
不,那是不可能的。T-SQL不支持这种语法