使用 select 语句将数据插入临时 table?

Insert data into temp table using select statement?

我想从 select 语句手动将数据插入到临时 table 中:

  Select into #temp from (select 1,2
    Union 
    select 2,4 
    Union 
    Select 8,12) as b

您需要为列命名(这里我将列命名为 ab):

Select a, b into #temp 
from 
(
     select a = 1, b = 2 
     Union 
     select 2, 4 
     Union 
     Select 8, 12
) as t

select * from #temp

a   b
-----
1   2
2   4
8   12

只有 UNION 的第一个 SELECT 子句需要明确的列名。