Help with stored procedure retrieves values from other stored procs and output

Hi, there,

I am looking for a little syntax help to get my stored procedure working.

Let's say I have this master sp called ud_m, and it calls two other sp, ud_m1, and ud_m2 from within. Each returns a singular value, and has its own logic for extracting the right data.

I am down to last step of retrieving the data from ud_m by calling it from the app(ssms for now).

Here is the sample code:

create procedure [dbo].[ud_m1]
as

begin
select 'val2'
end
go

create procedure [dbo].[ud_m2]
as

begin
select 'val1'
end
go

--this returns just fine
exec [dbo].[ud_m1]
exec [dbo].[ud_m2]

create procedure [dbo].[ud_m]
@out as varchar(100) output
as

begin

declare @Val1 varchar (10)
declare @Val2 varchar (10)

--do not want this next two to output directly, however they showed up anyway.:frowning:
exec @Val1 = [dbo].[ud_m1]
exec @Val2 = [dbo].[ud_m2]

--this part is for outout to calling app
--Select @Val1 , @Val2
Select @out = @Val1 + @Val2
end

go

declare @out as varchar(100)
exec [dbo].[ud_m] @out output
Select @out
--got
val2
val1
00
--I don't want line1 val2 and line 2 val1, but I do want 00 to be 'val2, val1', or 'val2val1'

drop procedure [dbo].[ud_m1]
drop procedure [dbo].[ud_m2]
drop procedure [dbo].[ud_m]

Thanks!

In your first two procedures - you need to define an output parameter and set the values to the output parameter. Then you can use those values in your outer procedure.

With that said - it might be better to create scalar functions to return the values instead of a stored procedure. It really depends on how this is going to be utilized.