Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop problem

Status
Not open for further replies.

habneh

Programmer
Mar 21, 2007
55
US
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
 
Add a line at the begining of the while loop which says select @name = null, @date = null.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top