sql语句递归查询会员的推荐或安置关系时报错:语句被终止。完成执行语句前已用完最大递归……
服务器范围的默认值为 100。如果指定 0,则没有限制。每一个语句只能指定一个 MAXRECURSION 值使用类似的语句:
例如:
;WITH cte AS
(
SELECT [AncestorID]=ParentID
,[DescendantID]=CustomerID
,[TreeLevel]=1
,[Part]=Region
,[AddDate]
,[OneGrade]
,[Pay_Level]
,[Pay_Org]
,Depth_p
,CalDate
FROM dbo.t_Pay where ParentID<>37 and (Pay_Level>0 or Pay_Org>0)
UNION ALL
SELECT [AncestorID]=ParentID
,[DescendantID]=d.DescendantID
,[TreeLevel]=d.TreeLevel+1
,[Part]=Region
,[AddDate]=d.AddDate
,[OneGrade]=d.[OneGrade]
,[Pay_Level]=d.Pay_Level
,[Pay_Org]=d.Pay_Org
,a.Depth_p
,CalDate=d.CalDate
FROM cte d
JOIN dbo.t_Pay a ON d.AncestorID=a.CustomerID
where a.Depth_p=d.Depth_p-1
)
SELECT AncestorID
,DescendantID
,TreeLevel
,Part
,AddDate
,OneGrade
,ISNULL(Pay_Level,0)
,ISNULL(Pay_Org,0)
,CalDate
FROM cte
OPTION(MAXRECURSION 0);
--服务器范围的默认值为 100。如果指定 0,则没有限制。每一个语句只能指定一个 MAXRECURSION 值使用类似的语句: