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 2000 Forums
 Transact-SQL (2000)
 Union Executing stored procedures?

Author  Topic 

Bryce Covert
Starting Member

12 Posts

Posted - 2005-07-08 : 13:54:11
Is it possible to union two stored procedures results?
IE

Exec storedprocedure1 'a'
Exec storedprocedure1 'b'

and have these results unioned together somehow?

Thanks!
Bryce

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-07-08 : 13:55:43
Yes, via temp tables although you don't need the UNION.

CREATE TABLE #Temp(...)

INSERT INTO #Temp
EXEC Sp1 ...

INSERT INTO #Temp
EXEC Sp2 ...

SELECT *
FROM #Temp

DROP TABLE #Temp

Tara
Go to Top of Page

vipinspg
Starting Member

12 Posts

Posted - 2005-07-09 : 07:59:08
You can go for table variable rather than temp tables.

DECLARE @v_records TABLE(.......)
INSERT INTO @v_records
EXEC sp1.....

INSERT INTO @v_records
EXEC sp2........

SELECT * from v_records

Vipins

.
Go to Top of Page

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2005-07-09 : 12:26:07
Apart from the fact that you'll get the following error:

EXECUTE cannot be used as a source when inserting into a table variable.

Mark
Go to Top of Page
   

- Advertisement -