SELECT INTO with Three UNIONed SELECTs

  • Hello,

    I have UNIONed three SELECT statements, and I need to take the results, and put them into a temp table. The SELECTs look something like this;

     

    SELECT

              fields

    FROM

              tables

    WHERE

              conditions

    UNION

    SELECT

              fields

    FROM

              tables

    WHERE

              conditions

    UNION

    SELECT

              fields

    FROM

              tables

    WHERE

              conditions

    Can I use SELECT INTO to take all of this and put it into a temp table?

    Thanks!

    CSDunn

  • Just wrap it with a select.

     

    select * into table_Name from

    (

    SELECT

              fields

    FROM

              tables

    WHERE

              conditions

    UNION

    SELECT

              fields

    FROM

              tables

    WHERE

              conditions

    UNION

    SELECT

              fields

    FROM

              tables

    WHERE

              conditions

    (

    SELECT

              fields

    FROM

              tables

    WHERE

              conditions

    UNION

    SELECT

              fields

    FROM

              tables

    WHERE

              conditions

    UNION

    SELECT

              fields

    FROM

              tables

    WHERE

              conditions

    ) A

    Tom

  • Thank you for your help!

    CSDunn

Viewing 3 posts - 1 through 2 (of 2 total)

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