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 2008 Forums
 Transact-SQL (2008)
 Extracting Stored Proc Data Dynamically

Author  Topic 

benramz
Starting Member

6 Posts

Posted - 2011-01-17 : 16:30:29
I am working with a program that contains a number of encrypted stored procedures (Off the shelf). I would like to know if it is possible to execute a stored proc from inside a select statement dynamically.

example: Store proc "Foo" returns DueAmtA, DaystilDue, DueAmtB when executed. execution is "Exec Foo <CustomerID>"

Select CustomerID, customername, customer address, (Exec Foo CustomerID) from Customer where customerid = 1234

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-17 : 16:43:05
It's not possible like that, but you can use a temp table to get the output of the stored procedure and then use the temp table in your query.


CREATE TABLE #Temp ...

INSERT INTO #Temp
EXEC ...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

benramz
Starting Member

6 Posts

Posted - 2011-01-17 : 16:55:01
Is it possible to wrap that with a cursor to get the data for all customerid's
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-17 : 17:13:20
Yes or just use a function instead. You can use a function directly in the query, like you've got now for the stored procedure.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -