Groups | Blog | Home
all groups > sql server (alternate) > july 2003 >

sql server (alternate) : SQL Query - Append data from two tables


kattukuyil NO[at]SPAM hotmail.com
7/7/2003 3:04:16 PM
I need to run a query which will pull data from two tables and append
it as one when it displays the result. The data are in two tables. But
the result set will be identical in terms of number of columns. I want
to display it one set below the other.

This is for pay history. From 2003 we have a new payroll system. Till
2002 we used to have a different system. But I need to run a query
which will pull the data for an employee for the last one year. So the
information is spread out between these two tables. Both these tables
are in SQL Server databases.

I want to write a Stored Procedure. I can use Shape/Append but I think
it doesnt work on QA/Stored Proc. It needs an OLEDB.

How can I write the query. I dont want to use temporary tables and do
inserts.

Thanks

Oscar Santiesteban Jr.
7/8/2003 1:23:36 AM
You can do a query with a UNION as in

Select * from
pay2002.dbo.table1
UNION
Select * from
pay2003.dbo.table1

This query assumes you that 2 separate databases like most payroll databases
have. This will produce one result set with data from 2 years.

[quoted text, click to view]

AddThis Social Bookmark Button