Need help with an insert query needs be a Insert Into a table selecting fields for a #temp but then joining other tables to get data for other columns

  • Hi,

    Need help with an insert query needs be a Insert Into a table selecting fields for a #temp but then joining other tables to get data for other columns.

    even a basic example would help like:

    insert into table1 a Select a.col1,a.col2

    from #tmp join table2 b

    ON a.col1 = b.col1

    Join table3 c ON b.col1 = c.col1

    Is this even possible on an insert select?

    Thanks in advance!

  • 1) insert into is helpful when destination table have similar columns as of source table.

    As well you have to make sure that column's datatype are matching while inserting records.

    So for example if your source table have 2 column and destination table also 2 columns and if both column have similar datatype then you can simple use

    'insert into dest_tblname(col1,col2) select * from source_tblname'.

    2) but if you want all/selected data to be exported to destination table without creating it, then you can use

    select *(or column names) into dest_tblname from source_tblname.

    ----------
    Ashish

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

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