0

I have query which looks like

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

So my question how I can insert from this CTE?

Andrey
  • 1,629
  • 13
  • 37
  • 65
  • See http://stackoverflow.com/questions/15600154/microsoft-sql-server-insert-from-select-query and http://stackoverflow.com/questions/3306096/combining-insert-into-and-with-cte. – bgoldst Mar 30 '15 at 13:47
  • 2
    just add insert into myTable between the CTEs and the select.(without the VALUES clause) – mxix Mar 30 '15 at 13:48

1 Answers1

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
M.Ali
  • 67,945
  • 13
  • 101
  • 127