sql server中变量要先申明后赋值:
申明局部变量语法:declare @变量名 数据类型;例如:declare @num int;
赋值:有两种方法式(@num为变量名,value为值)
set @num=value; 或 select @num=value;
如果想获取查询语句中的一个字段值可以用select给变量赋值,如下:
select @num=字段名 from 表名 where ……
第一种用法:set @num=1; 或set @num:=1; //这里要使用变量来保存数据,
第二种用法:select @num:=1; 或 select @num:=字段名 from 表名 where ……
注意上面两种赋值符号,使用set时可以用“=”或“:=”,但是使用select时必须用“:=赋值”
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/bigdata/4493.html