I was replacing a cursor with a while loop and I am facing one minor problem but its impact is so big.
see the code
//variables declared here
select @id = min(id) from table1
while @id is not null
begin
select @name = name
@date = date
from table1
where id = @id
//do some thing
select @id = min(id) from table1 where id > @id
end
here is the problem I faced
when values for both name and date are not null it works fine but if one of them are null, the values for the variables @name or @date holds the previous data instead of null, that results a big headache.
how can I correct this to make sure that whenever one of the column values is null, they won't hold the previous value
Thanks
see the code
//variables declared here
select @id = min(id) from table1
while @id is not null
begin
select @name = name
@date = date
from table1
where id = @id
//do some thing
select @id = min(id) from table1 where id > @id
end
here is the problem I faced
when values for both name and date are not null it works fine but if one of them are null, the values for the variables @name or @date holds the previous data instead of null, that results a big headache.
how can I correct this to make sure that whenever one of the column values is null, they won't hold the previous value
Thanks