从多个CTE插入

时间:2015-03-30 13:45:39

标签: sql sql-server database common-table-expression

我的查询看起来像

with cte
(
code
),
cte1
(
code
),
cte2
(
code
)
select cte.1, cte2.1, cte1.2,cte1.3
from cte left outer join cte1 on cte.id=cte1.id
left outer join cte2 on cte.id=cte2.id

所以我的问题是如何从这个CTE插入?

1 个答案:

答案 0 :(得分:1)

with cte
(
code
),
cte1
(
code
),
cte2
(
code
)
INSERT INTO TableName(Col1 , Col2 , Col3, Col4)   --<-- here
select cte.1, cte2.1, cte1.2,cte1.3
from cte 
left outer join cte1 on cte.id=cte1.id
left outer join cte2 on cte.id=cte2.id