Hello,
i need to execute a stored procedure from another stored procedure.
For example:
StoredProcedure1: Returns a table with columns "year" and "value".
StoredProcedure2: Also returns a table with columns "year" and "value".
In Stored Procedure3: I would like to use the results from StoredProcedure1 and StoredProcedure2 and join them.
Can somebody give me an example how to execute a stored procedure from another one and use the result table for a new command?
Kind regards and thanks,
carsaw
hi,
first off all let me clarify here - you cannot return table from a stored procedure you can use output variables but not the table.
what i would suggest you from your qeustion is - sp3 is main sp for you which needs data from sp1 & sp2 right
in that case let sp3 contain a temporary table #temptable with required columns
--parent proc
alterproc p1
as
Createtable #tempu
(
pidintidentity(1,1),
namesvarchar(50)
)
begin
insert #tempu(names)
exec tempinserter
select*from #tempu
end
--2nd proc
alterproc tempinserter
as
Createtable #temp2
(
pidintidentity(1,1),
namesvarchar(50)
)
insert #temp2
values('satish')
select namesfrom #temp2
return
--similarly create 3rd one then
exec p1 --the parent proc
hope it helps
also keep in mind to drop #temp tables at end of execution
regards,
satish.
|||like i've called tempinserter in parent proc you can call other procs in the same manner.
regards,
satish
No comments:
Post a Comment