Reply to Is there any way in a sproc to LOOP thru the records of a table ?

Your name:

Reply:


Posted by Radu on 09/21/05 17:59

Hi. It seems to be very simple, actually, but I don't know if it is
feasible in TSQL. I have a sproc which gathers in one place many calls
to different other sprocs, all of them taking a 'StoreGroupe'
parameter. I would like to add a case where if the call has NO
StoreGroupe parameter, the sproc should LOOP thru all records in table
StoreGroupeTable, read the column StoreCode, and pass that value as a
param to the other sprocs, as in:

CREATE PROCEDURE MySproc

(
@StoreGroupe nvarchar(6) = NULL
)

AS
if (@StoreGroupe is not null)
Begin
Exec _Sproc1 @StoreGroupe
Exec _Sproc2 @StoreGroupe
Exec _Sproc3 @StoreGroupe
Exec _Sproc4 @StoreGroupe
...............
End
Else
Begin
A 'Group Code' has NOT been specified
I want to take all the StoreGroups in table
StoreGroupeTable, in turn.
I would like to do SOMETHING LIKE THIS:
Do While not [StoreGroupeTable].EOF
Read [Code] from [StoreGroupeTable]
Set @StoreGroupe = The value I just read
Exec _Sproc1 @StoreGroupe
Exec _Sproc2 @StoreGroupe
Exec _Sproc3 @StoreGroupe
Exec _Sproc4 @StoreGroupe
...............
Loop
End
GO

Is that feasible in a sproc, or do I have to do this in the client
(ADO) ?

Thanks a lot.
Alex.

[Back to original 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

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