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 2000 Forums
 SQL Server Development (2000)
 How to Treat an SP

Author  Topic 

mikebird
Aged Yak Warrior

529 Posts

Posted - 2008-10-21 : 12:00:30
If I run an SP like this:
exec epex3 '08-09-01', '08-10-31'

what can I do with the output? I know the final statement might be a SELECT or a PRINT and I'll see a message or a table but when I see the outcoming table, how do I run again with a WHERE clause, as you do when developing a SELECT query? Can I treat the EXEC statement above as a table and add a WHERE to it? I think not.

SELECT colunmx FROM ( exec epex3 '08-09-01', '08-10-31' )
is invalid, yes?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-21 : 12:26:39
You can put the results of the stored procedure into a table (permanent or # temp)

CREATE TABLE #t1 (c1 int, c2 varchar(5), ...)

INSERT INTO #t1 (c1, c2, ...)
EXEC sp1 @var1 = 5, @var2 = 'yes'

SELECT *
FROM #t1
WHERE ...

DROP TABLE #t1

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

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-21 : 13:05:21
or you can even use table valued UDFs instead of stored procedures in which case you can use them in select queries just like a table with WHERE conditions and also join other tables. the syntax will be like

SELECT colunmx FROM dbo.epex3('08-09-01', '08-10-31')
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-22 : 04:14:00
or point 2
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -