SQL 1 多个变量的 SET 语句,如声明语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7193777/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 11:53:00 来源:igfitidea点击:
1 SET statement for multiple variables like declare statement
提问by mameesh
Is there a way to set all variables with one set statment, like you can with a declare statement?
有没有办法用一个 set 语句设置所有变量,就像使用声明语句一样?
For example:
例如:
Declare @Test VARCHAR(10),
@Test2 VARCHAR(10),
@Test3 INT
SET @Test = 'test'
SET @Test2 = 'Test2'
SET @Test3 = 1
Where I want to do something like the below, but the below does not work:
我想做类似下面的事情,但下面的不起作用:
Set @Test = 'test',
@Test2 = 'Test2',
@Test3 = 3
回答by p.campbell
Instead of SET
, use SELECT
.
而不是SET
,使用SELECT
。
SELECT @Test = 'test',
@Test2 = 'Test2',
@Test3 = 3;
Here's a great article on SET vs SELECT in SQL Server / TSQL.