I 'm trying to write a simple while loop.
declare @colname as varchar =''
while @colname is not null
begin
Select @colname = col1
FROM Table1
WHERE col1 in ('test1','test2','test3')
if(@colname is not null)
begin
exec sp('@colname')
end
end
It seems that it is getting the value of the last row it finds and keeps looping. Any suggestions on how to fix this.
UPDATE: I 'm calling a stored procedure for each value that is returned by the select statement. Instead of while the logic was written using cursors. So in effect trying to convert cursor to while loop. Thanks