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
 General SQL Server Forums
 New to SQL Server Programming
 Stored procedure in a Select Statement

Author  Topic 

vishu.av
Starting Member

26 Posts

Posted - 2007-04-23 : 05:13:08
Hi All,

Can i run a stored procedure with in a SELECT statement
like below?

Select * from EmployeeDetails where EmployeeName in (.. Some Stored procedure to return me some set of Employee Names)

Is there a better way of doing it?
Thanks in advance

vishu
Bangalore

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-23 : 05:16:26
No, you can not.
But... You can store the result of an SP in a temp table

INSERT #Temp
EXEC <SP>

and use the table with a JOIN as normal.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-23 : 05:19:12
Not directly.

You can store the output of Stored Proc in a temp table like:

Create table #temp
(
... -- define columns here
)

Insert into #temp
EXEC sp_something(...)


And then use temp table in SELECT statement like below:

Select ed.* from EmployeeDetails ed Join #temp t 
on ed.EmployeeName = t.EmployeeName



PesoBot again overtook me!

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -