;With cte1(…) as (…)
<这里无论用什么分割都不行> with cte2(…) as(…)这样错误
必须这样写
;<如果with 不是第一句> with cte1(…) as (…), cte2(…) as
(…)
3. cte定义后必须马上跟 select …. From
这样的语句,哪怕from 跟CTE无关(这点最变态)
以下语句是错误的
;with cte1(...) as (...);
print 'test';
以下语句是正确的
;with cte1(...) as (...);
select top 1 * from cte1;
print 'ok';