SQL Query - Append data from two tables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Girish

    SQL Query - Append data from two tables

    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

    GIRISH
  • Oscar Santiesteban Jr.

    #2
    Re: SQL Query - Append data from two tables

    You can do a query with a UNION as in

    Select * from
    pay2002.dbo.tab le1
    UNION
    Select * from
    pay2003.dbo.tab le1

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

    "Girish" <kattukuyil@hot mail.com> wrote in message
    news:b2bb38a.03 07071404.545407 91@posting.goog le.com...[color=blue]
    > 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
    >
    > GIRISH[/color]


    Comment

    Working...