首页 > 代码库 > 语句被终止。完成执行语句前已用完最大递归 100

语句被终止。完成执行语句前已用完最大递归 100

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 ALL10     SELECT cte.EmployeeID, cte.ManagerID, cte.Title11     FROM cte 12     JOIN  dbo.MyEmployees AS e 13         ON cte.ManagerID = e.EmployeeID14 )15 --Uses MAXRECURSION to limit the recursive levels to 216 SELECT EmployeeID, ManagerID, Title17 FROM cte18 OPTION (MAXRECURSION 2);19 GO

 

文章参考:http://bbs.csdn.net/topics/390412714

语句被终止。完成执行语句前已用完最大递归 100