Use Multiple CTE

后端 未结 1 1918
北荒
北荒 2021-01-05 04:37

Cannot figure out how to use multiple CTE

This fails

; with [cteOne] as (
  select 1 as col
),
  [cteTwo]  as (
  select 2 as col
)
select \'yesA\         


        
1条回答
  •  抹茶落季
    2021-01-05 05:24

    The first one fails because a CTE or set of CTEs can only be followed by a single statement.

    You could rewrite it as

    ; with [cteOne] as (
      select 1 as col
    )
    select 'yesA' where exists (select * from [cteOne])
    
    ; with [cteTwo]  as (
      select 2 as col
    )
    select 'yexB' where exists (select * from [cteTwo])
    

    0 讨论(0)
提交回复
热议问题