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
 executing stored procedure in a select

Author  Topic 

aomar
Starting Member

6 Posts

Posted - 2008-06-12 : 09:03:22
i wanna execute a stored procedure in a select and use its return type
i.e

select name from table1 where id = sp 1,1

i executed it and occurred an error

help me pls

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-12 : 09:28:42
Have you used output parameter in the procedure?

Declare @id int
EXEC sp 1,1,@id output
select name from table1 where id = @id


Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-12 : 09:29:13
you cant use sps in select statements. you need to do it like this:-

INSERT INTO #temp
exec sp 1,1
select name from table1 where id in (select id from #temp)
also ensure #temp has same structure as return set of sp

Alternatively you can use a table valued udf in which case you can do

select name from table1 where id in (select val from udf(1,1))
Go to Top of Page
   

- Advertisement -