mssql sqlserver 模拟for循环的写法

转自:http://www.maomao365.com/?p=6567

摘要:
下文讲述sql脚本模拟for循环的写法,如下所示:

 /*
for样例
for('初始值','条件','执行后自增')
通过对for语句的结构分析,我们可以采用以下
while 结构来实现for循环,
--------------------------
初始值
while(条件)
begin
  执行后自增
end
--------------------------
例:使用while输出10的遍历
*/
declare @i int=1  --初始值
while (@i<=10) --条件
begin
  print '@i的值:'
  print @i
  set @i=@i+1 ---执行后自增
end

猜你喜欢

转载自www.cnblogs.com/lairui1232000/p/9475481.html