SQL SERVER中变量声明的命令是什么
答案:2 悬赏:10 手机版
解决时间 2021-02-24 18:02
- 提问者网友:雪舞兮
- 2021-02-23 17:50
SQL SERVER中变量声明的命令是什么
最佳答案
- 五星知识达人网友:毛毛
- 2021-02-23 19:08
declare @变量名 类型
比如给你写个例子,declare的那些都是生明变量,set是给变量赋值
declare @a int
declare @b int
declare @c int
declare @d int
declare @str int
set @str=0
while @str<=9999
begin
set @a=cast(substring(right("0000"+cast(cast(@str as varchar) as varchar),4),1,1) as int)
set @b=cast(substring(right("0000"+cast(cast(@str as varchar) as varchar),4),2,1) as int)
set @c=cast(substring(right("0000"+cast(cast(@str as varchar) as varchar),4),3,1) as int)
set @d=cast(substring(right("0000"+cast(cast(@str as varchar) as varchar),4),4,1) as int)
if (@a*7+@b*9+@c*10+@d*5+222)%11=3
begin
print ("a="+cast(@a as varchar)+" b="+cast(@b as varchar)+" c="+cast(@c as varchar)+" d="+cast(@d as varchar))
end
set @str=@str+1
end
比如给你写个例子,declare的那些都是生明变量,set是给变量赋值
declare @a int
declare @b int
declare @c int
declare @d int
declare @str int
set @str=0
while @str<=9999
begin
set @a=cast(substring(right("0000"+cast(cast(@str as varchar) as varchar),4),1,1) as int)
set @b=cast(substring(right("0000"+cast(cast(@str as varchar) as varchar),4),2,1) as int)
set @c=cast(substring(right("0000"+cast(cast(@str as varchar) as varchar),4),3,1) as int)
set @d=cast(substring(right("0000"+cast(cast(@str as varchar) as varchar),4),4,1) as int)
if (@a*7+@b*9+@c*10+@d*5+222)%11=3
begin
print ("a="+cast(@a as varchar)+" b="+cast(@b as varchar)+" c="+cast(@c as varchar)+" d="+cast(@d as varchar))
end
set @str=@str+1
end
全部回答
- 1楼网友:逐風
- 2021-02-23 20:21
SQL SERVER中变量声明的命令是:
declare 变量名 变量类型[,变量名 变量类型]
如:declare @id int,@mc varchar(20)
声明 @id 为整形;,@mc为字符(20位)。
一个 declare 可声明一个或多个变量
变量名前一定要加“@”符号。
declare 变量名 变量类型[,变量名 变量类型]
如:declare @id int,@mc varchar(20)
声明 @id 为整形;,@mc为字符(20位)。
一个 declare 可声明一个或多个变量
变量名前一定要加“@”符号。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯