Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sallymac
Starting Member
3 Posts |
Posted - 2008-10-13 : 17:12:34
|
Hello,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.[Code]declare @loop int, @csv varchar(max)set @loop = @@rowcountwhile @loop =1beginupdate top 1000 mytable set updatestatus = 1 where updatestatus = 0set @csv = select top 1000Select @csv = isnull(@csv + ', ', '') + productsFrom myTableWhere updatestatus = 1---pass @csv to billing function then log[/Code]endthanks |
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2008-10-13 : 19:13:05
|
What is special about your processing that you need to do it in a function? Ideally, you don't loop through a table processing each record; you apply the processing to the set of records in the table.=======================================It is impossible to imagine Goethe or Beethoven being good at billiards or golf. -H.L. Mencken, writer, editor, and critic (1880-1956) |
|
|
|
|
|