我需要结合两个不同的递归查询。有些想法:
with cte1 as
( select....
....
....
)
select * from cte1
union all
with cte2 as
( select....
....
....
)
select * from cte2
我该怎么办?我收到错误: 关键字“WITH”附近的语法不正确。
你知道任何workaroud吗?我试图通过互联网搜索,但我找不到它..
答案 0 :(得分:9)
订单应该是:
;WITH Cte1 AS
(
....
),
Cte2 AS
(
....
)
SELECT * FROM Cte1
UNION ALL
SELECT * FROM Cte2
您的所有CTE
都需要在系列语句的开头。