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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Using select records as input parameters

Author  Topic 

Scott
Posting Yak Master

145 Posts

Posted - 2008-08-29 : 12:23:32
Excuse the dumb Friday moment.

I have a select statement:
SELCET A, B FROM Table

That returns say 10 records. I also have a stored procedure:
usp_proc a, b

That accepts 2 parameters. As you may have guessed I want to execute the procedure for every row returned by the select statement.

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2008-08-29 : 12:35:41
Unfortunately you will need to use a loop if you are certain that the Stored Procedure is your only option.

In most cases the procedure can be converted to a function, or Removed Completly where you can then run it as part of the query with a huge performance increases.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-29 : 12:46:32
quote:
Originally posted by Scott

Excuse the dumb Friday moment.

I have a select statement:
SELCET A, B FROM Table

That returns say 10 records. I also have a stored procedure:
usp_proc a, b

That accepts 2 parameters. As you may have guessed I want to execute the procedure for every row returned by the select statement.


may be you could try like this
SELCET A, B FROM Table t
CROSS APPLY(SELECT * FROM OPENROWSET(....,EXEC usp_proc t.a, t.b))tmp



for full syntax of openrowset refer books online
Go to Top of Page
   

- Advertisement -