You are here: Re: Is there any way in a sproc to LOOP thru the records of a table ? « MsSQL Server « IT news, forums, messages
Re: Is there any way in a sproc to LOOP thru the records of a table ?

Posted by Simon Hayes on 09/21/05 18:09

You can do this using a cursor - executing a stored proc repeatedly for
each value in a column is one of the (few) cases where they're useful.
In performance terms it would probably be better to rewrite proc1,
proc2 etc. to operate on a set of values using set-based code (but that
may not be possible, of course, depending on what the procs are doing).

declare @StoreGroupe int

declare cur cursor local static
for select SomeCode from dbo.StoreGroupes

open cur
fetch next from cur into @StoreGroupe
while @@fetch_status = 0
begin
exec dbo.proc1 @StoreGroupe
exec dbo.proc2 @StoreGroupe
-- etc.
fetch next from cur into @StoreGroupe
end

close cur
deallocate cur

Simon

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация