Union

  • Hi,

    i have one temp table with id. i need to take records from two select statement with Union for same id

    how can i take it.

    for ex

    #temp table i have 100 id

    select A,B, '' as C from table1

    where id= id from temp table

    Union

    select '' A, '' B, C from table 2

    where id= id from temp table

    for all 100 records

  • Are you doing this in SSIS?

    Can't you just execute the SQL statement you have in an Execute SQL Task?

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • What are you doing with the records after the UNION?

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Try this:

    select A,B, '' as C from table1

    where id in (select id from temp table)

    Union

    select A, B, C from table 2

    where id in (select id from temp table)

  • i am trying to merge the colums which is taken from two queries.

  • pmckarur (1/19/2011)


    i am trying to merge the colums which is taken from two queries.

    As said before, can't you just execute a TSQL UNION statement in an Execute SQL Task?

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply