While loop in T-SQL
Here is a simple example of While loop
Declare @temp tinyint = 1
while (@temp < 11)
begin
print cast(@temp as varchar(2)) + ' X 2 = ' + cast(@temp * 2 as char)
set @temp += 1
end
The above code will be having the following output:
Output
1 X 2 = 2
2 X 2 = 4
3 X 2 = 6
4 X 2 = 8
5 X 2 = 10
6 X 2 = 12
7 X 2 = 14
8 X 2 = 16
9 X 2 = 18
10 X 2 = 20
No comments:
Post a Comment