Insert into … values ( SELECT … FROM … )

前端 未结 26 2430
我在风中等你
我在风中等你 2020-11-21 05:40

I am trying to INSERT INTO a table using the input from another table. Although this is entirely feasible for many database engines, I always seem to struggle t

26条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-21 05:57

    I actually prefer the following in SQL Server 2008:

    SELECT Table1.Column1, Table1.Column2, Table2.Column1, Table2.Column2, 'Some String' AS SomeString, 8 AS SomeInt
    INTO Table3
    FROM Table1 INNER JOIN Table2 ON Table1.Column1 = Table2.Column3
    

    It eliminates the step of adding the Insert () set, and you just select which values go in the table.

提交回复
热议问题