SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stored procedure in a Select Statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vishu.av
Starting Member

India
26 Posts

Posted - 04/23/2007 :  05:13:08  Show Profile  Reply with Quote
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

Sweden
30265 Posts

Posted - 04/23/2007 :  05:16:26  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
5581 Posts

Posted - 04/23/2007 :  05:19:12  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
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"

Edited by - harsh_athalye on 04/23/2007 05:23:00
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000