How to set the maxrecursion option for a CTE inside a Table-Valued-Function

后端 未结 6 1494
粉色の甜心
粉色の甜心 2020-11-29 08:01

I\'m facing a problem declaring the maxrecursion option for a CTE inside a TVF.

Here is the CTE (a simple calendar):

DECLARE @DEBUT DATE = \'1/1/11\'         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 08:37

    Old issue but... I just wanted to clarify why OPTION(MAXRECURSION x) is not allowed in an in-line table-valued function. This is because iTVF's get inlined when you use them in a query. And, as we all know, you cannot put this option anywhere else save at the very end of the query. This is THE reason it will never be possible to put it inside an iTVF (unless the parser and/or algebrizer does some magic behind the scenes, which I don't think it will any time soon). mTVF's (multi-statement table-valued functions) is a different story because they don't get inlined (and are so slow that they should never be used in queries; it's OK to use them in an assignment to a variable, though, but then again---beware of loops!).

提交回复
热议问题