var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Walk through a table one record at a time without using a cursor
Hi, I'm a newbie in SQL Server 7.0, can someone tell me how do I walk through a table one record at a time without using a cursor please.
You can use the primary key - this is for an ID but will work on any primary key.
declare @id int, @maxid int
select @id = 0, @maxid = max(id) from tbl
while @id < @maxid
select @id = min(id) from tbl where id > @id
select * from tbl where id = @id
This also works with a filter - just include it in the selects.
You can also create a temp table with the records and with an identity on it. This can often be more efficient and clearer as you can preprocess all the records before executing the loop.