Subject | Is there a way to pass a result set as a parameter? |
---|---|
Author | Eduardo A. Salgado |
Post date | 2008-05-09T16:31:41Z |
Let's say I have a very simple stored procedure:
CREATE PROCEDURE UpdateByParentID (
AValue integer,
AParentID integer)
AS BEGIN
UPDATE SomeTable SET SomeColumn = :AValue WHERE
ParentID = :AParentID;
END;
...and I want to call it with a number of ParentIDs derived from a
result set. Something like:
EXECUTE PROCEDURE
UpdateByParentID (1, 'SELECT ParentID FROM SomeOtherTable WHERE
SomeOtherID BETWEEN 1 AND 10')
or
EXECUTE PROCEDURE
UpdateByParentID (1, 'SELECT ParentID FROM SomeOtherTable WHERE
SomeOtherCost BETWEEN 50 AND 200')
or...
Well, you get the idea. The query that generates the list of
ParentIDs, can be as simple or complicated as I would like. Is
there a way to pass a result set as a parameter? There may be
hundreds or thousands of ParentIDs that need to be passed.
Any help would be appreciated.
Thanks!
-Eduardo
CREATE PROCEDURE UpdateByParentID (
AValue integer,
AParentID integer)
AS BEGIN
UPDATE SomeTable SET SomeColumn = :AValue WHERE
ParentID = :AParentID;
END;
...and I want to call it with a number of ParentIDs derived from a
result set. Something like:
EXECUTE PROCEDURE
UpdateByParentID (1, 'SELECT ParentID FROM SomeOtherTable WHERE
SomeOtherID BETWEEN 1 AND 10')
or
EXECUTE PROCEDURE
UpdateByParentID (1, 'SELECT ParentID FROM SomeOtherTable WHERE
SomeOtherCost BETWEEN 50 AND 200')
or...
Well, you get the idea. The query that generates the list of
ParentIDs, can be as simple or complicated as I would like. Is
there a way to pass a result set as a parameter? There may be
hundreds or thousands of ParentIDs that need to be passed.
Any help would be appreciated.
Thanks!
-Eduardo