Self-joining query to find descendants of a node syntax issue

无人久伴 提交于 2019-12-07 01:38:28

Read the fabulous error message!

It clearly says:

Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.

So: terminate your previous statement with a semicolon, and you should be fine!

DECLARE @StepId INT = 3

; WITH cteRecursion
     AS (SELECT
             Stepid, 1 AS Level
         FROM
             Step
         WHERE
             StepId = @StepId
        .......

You need a ; before the WITH or else you get this error.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!