WHILE @cnt < cnt_total
BEGIN
{.câu lệnh thực thi.}
SET @cnt = @cnt + 1;
END;
Parameters :
Consider an example of how to simulate a FOR loop in SQL Server (Transact-SQL) with a WHILE loop.
DECLARE @cnt INT = 0;
WHILE @cnt < 10
BEGIN
PRINT 'Vi du mo phong vong lap FOR trong SQL Server cua TipsMake.com';
SET @cnt = @cnt + 1;
END;
PRINT 'Ket thuc mo phong vong lap FOR cua TipsMake.com';
GO
In the example using this WHILE command, the loop will terminate when @cnt reaches the value of 10.
Last lesson: WHILE loop in SQL Server
Next article: BREAK (Control Disconnect) command in SQL Server