469,329 Members | 1,444 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,329 developers. It's quick & easy.

Exec stored proc from select in another stored proc

Hello everyone. I've been trying to find if this is even possible but nothing I've found has really helped.

I've got a stored proc with a few input parameters and one output parameter. I would like to call this proc from another proc and have proc 2 return the result of proc1 as a column. Some thing like this

create procedure Proc1
@Input1 numeric,
@Input2 varchar(20),
@Input3 money output
Select @Input3 = Amount from Table where ...

create procedure Proc2
@Input4 numeric,
@Input5 numeric
Select Column1, Column2, (exec Proc1 input1,input2, input3 output) as Column3
from table 2
where ...

Is this sort of thing even possible? Basically I need some of the results from Proc2 as inputs into Proc1 and return a single result from Proc2.

Thanks in advance.

Dec 6 '06 #1
3 6223
1,017 Expert 512MB
Yes it is possible but it should be not a stored procedure but a function.
Dec 6 '06 #2
1,017 Expert 512MB
-- Try this
CREATE FUNCTION Proc1 (@Input1 numeric,
@Input2 varchar(20))


SELECT @Str = 'Your imput is : Input1 = ' + cast(@Input1 as varchar(10)) + ' Input2 = ' + @Input2


-- This could be executed from any stored procedure. You can pass parameters as column names
select dbo.Proc1(1, 'Hello')[/PHP]
Dec 6 '06 #3
Thanks for the quick reply. I hadn't even considered doing a function, since I have never needed one before. Well maybe I have but just found another way to do it.

Thanks again.

Dec 6 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Chip Mayan | last post: by
6 posts views Thread by David Lozzi | last post: by
45 posts views Thread by John | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.