create table using select statement in sql server 2005

  • How to create sql table using a below select statement(4 tables)

    select T1.column1,T1.column2, T3.column3, T2.column4,

    t2.column5,T1.column6, T3.column7, T4.column8

    from table1 T1, table2 T2, table3 T3, table4 T4

    WHERE T1.column1 = T2.column1 AND t1.column2 =T3.column2

    AND T3.column7 = T4.column7 AND T3.Accountid =1

    Please advice

  • Hi,I think you could use select... into ... because your column names are all unique. Something like this.

    select

    T1.column1,

    T1.column2,

    T3.column3,

    T2.column4,

    t2.column5,

    T1.column6,

    T3.column7,

    T4.column8

    into

    NewTable

    from

    table1 T1, table2 T2, table3 T3, table4 T4

    WHERE

    T1.column1 = T2.column1

    AND t1.column2 = T3.column2

    AND T3.column7 = T4.column7

    AND T3.Accountid =1

    NB

    1 not tested

    2 join syntax is old style, its easier to read if the JOIN is split out from the WHERE

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

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