The while ().. begin..end is the best way to preform loops within
a stored procedure. Note that declared variables in T-SQL need to
be initialized.
create proc proc_looper (@loops int) as
declare @count integer,
@power2 float
select @count = 0, @power2 = 1
while (@count < @loops)
begin
select @power2 = @power2 * 2
select @count = @count + 1
end
select 'Result is: ', @power2
return
go
|
|