Unanswered: Best way to loop through multiple records
I have about 20,000 records in my db i want to loop through, process one by one by a function and then log.
My question is whats the best way to loop through.
declare @loop int, @csv varchar(max)
set @loop = @@rowcount
while @loop =1
update top 1000 mytable set updatestatus = 1 where updatestatus = 0
set @csv = select top 1000
Select @csv = isnull(@csv + ', ', '') + products
Where updatestatus = 1
---pass @csv to billing function then log