By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,592 Members | 1,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,592 IT Pros & Developers. It's quick & easy.

Exec stored proc from select in another stored proc

P: 3
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
as
Select @Input3 = Amount from Table where ...
go

create procedure Proc2
@Input4 numeric,
@Input5 numeric
as
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.

Stephen
Dec 6 '06 #1
Share this Question
Share on Google+
3 Replies


iburyak
Expert 100+
P: 1,017
Yes it is possible but it should be not a stored procedure but a function.
Dec 6 '06 #2

iburyak
Expert 100+
P: 1,017
[PHP]
-- Try this
CREATE FUNCTION Proc1 (@Input1 numeric,
@Input2 varchar(20))
RETURNS VARCHAR(255)
AS
BEGIN


DECLARE @Str VARCHAR(255)

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

RETURN @Str
END

-- 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

P: 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.

Stephen
Dec 6 '06 #4

Post your reply

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