Create view with recursive CTE

Lora 200 Reputation points
2023-11-30T03:26:31.48+00:00

Trying to define a recursive cte inside a view.

However, there is an error: Incorrect syntax near the keyword 'OPTION'.

If I remove the OPTION(maxrecursion 100) then there is no error.

Is there any solutions to add this OPTION(maxrecursion 100) without error message?

SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. LiHongMSFT-4306 31,566 Reputation points
    2023-11-30T03:51:16.6466667+00:00

    Hi @Lora

    You cannot specify the maxrecursion option inside a view.

    You could first create your view without the MAXRECURSION option, and then query the view include the MAXRECURSION option like this:

    SELECT  columns
    FROM    your_view
    OPTION (maxrecursion 100);
    

    Best regards,

    Cosmog Hong

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.