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)
 Simple stored procedure questien

Author  Topic 

patsymcox
Starting Member

2 Posts

Posted - 2010-01-30 : 12:21:44
I need a stored procedure for a report which will query 3 tables, for eg

select a1,a2 from table a
select b1,b2,b3 from table b
select c1,c2 from table c

Is there any way to create a temporary table with fields a1,a2,b1,b2,b3,c1,c2 and fetch data into the temporary table and return it. so I get a uniform data structure as result set rather than multiple result sets.

Plz help

Kristen
Test

22859 Posts

Posted - 2010-01-30 : 12:28:22
[code]
SELECT a1, a2, NULL AS b1, NULL AS b2, NULL AS b3, NULL AS c1, NULL AS c2
FROM TableA
UNION ALL
SELECT NULL AS a1, NULL AS a2, b1, b2, b3, NULL AS c1, NULL AS c2
FROM TableB
UNION ALL
SELECT NULL AS a1, NULL AS a2, NULL AS b1, NULL AS b2, NULL AS b3, c1, c2
FROM TableC
[/code]
Go to Top of Page

patsymcox
Starting Member

2 Posts

Posted - 2010-01-30 : 22:59:04
Thanks much. It helped!
Go to Top of Page
   

- Advertisement -