在MSSQL中使用(Transact-SQL)SQL语句来使用循环的方式。
语法:

1
2
3
4
5
6
7
DECLARE @cnt INT = 0;

WHILE @cnt < cnt_total
BEGIN
{...statements...}
SET @cnt = @cnt + 1;
END;

参数说明:
cnt_total 循环的最大次数

示例:

1
2
3
4
5
6
7
8
9
10
DECLARE @cnt INT = 0;

WHILE @cnt < 10
BEGIN
PRINT 'Inside simulated FOR LOOP on devnp.com';
SET @cnt = @cnt + 1;
END;

PRINT 'Done simulated FOR LOOP on devnp.com';
GO