我正在简化复杂的select语句,所以我想我会使用常用的表表达式.
声明一个cte工作正常.
WITH cte1 AS (
SELECT * from cdr.Location
)
select * from cte1
Run Code Online (Sandbox Code Playgroud)
是否可以在同一个SELECT中声明和使用多个cte?
即这个sql给出了一个错误
WITH cte1 as (
SELECT * from cdr.Location
)
WITH cte2 as (
SELECT * from cdr.Location
)
select * from cte1
union
select * from cte2
Run Code Online (Sandbox Code Playgroud)
错误是
Msg 156, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'WITH'.
Msg 319, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'with'. If this statement is a common table …Run Code Online (Sandbox Code Playgroud) sql t-sql sql-server common-table-expression sql-server-2008