sql語句遞歸查詢會員的推薦或安置關系時報錯:語句被終止。完成執行語句前已用完最大遞歸……
服務器范圍的默認值為 100。如果指定 0,則沒有限制。每一個語句只能指定一個 MAXRECURSION 值使用類似的語句:
例如:
1 USE AdventureWorks2008R2; 2 GO 3 --Creates an infinite loop 4 WITH cte (EmployeeID, ManagerID, Title) as 5 ( 6 SELECT EmployeeID, ManagerID, Title 7 FROM dbo.MyEmployees 8 WHERE ManagerID IS NOT NULL 9 UNION ALL 10 SELECT cte.EmployeeID, cte.ManagerID, cte.Title 11 FROM cte 12 JOIN dbo.MyEmployees AS e 13 ON cte.ManagerID = e.EmployeeID 14 ) 15 --Uses MAXRECURSION to limit the recursive levels to 2 16 SELECT EmployeeID, ManagerID, Title 17 FROM cte 18 OPTION (MAXRECURSION 2); 19 GO
