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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Union Between Stored Procedures

Author  Topic 

rcr69er
Constraint Violating Yak Guru

327 Posts

Posted - 2008-05-30 : 04:29:00
Hi Guys

Is it possible to perform a Union between seperate stored procedures within one stored procedure?

For example:

I have the following procedure:
CREATE PROCEDURE [getMonthlyBreakdown]
(@Period DATETIME)
AS


EXEC [getTotalNumberOfIndividualOrders] @Period
EXEC [getCountOfOrderLine] @Period
EXEC [getCountOfDespatchedItems] @Period

GO

DECLARE @Period DATETIME
SET @Period = '2008-04-01'
EXEC [getMonthlyBreakdown] @Period


Is it possible to perform a union within the stored procedure with 3 stored procedures being called? All 3 have the same number of output rows.

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-30 : 05:17:02
Yup you can place the results of three SPs into temporary tables and take union among them.
Go to Top of Page

rcr69er
Constraint Violating Yak Guru

327 Posts

Posted - 2008-05-30 : 05:33:13
Hi

Thanks, but how would you do that?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-30 : 05:47:49
using
INSERT #Table
EXEC SPName paramvaluelist...
Go to Top of Page

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2008-05-30 : 05:59:54
Hello,
Look into this small example code.....

create proc sample
as
declare @tab table(col1 int,col2 int)
insert into @tab(col1,col2)
select 1,2 union
select 2,3 union
select 3,4

select * from @Tab
Go

declare @tab1 table(col1 int,col2 int)
insert into @Tab1
exec sample

Using the above example you can get entire SP result into a Temporary table, After that you can join easily...

Ganesh
Go to Top of Page
   

- Advertisement -