WITH [Rollup]
AS
(
SELECT id, parent FROM RollupAccount 
WHERE id = 1000
UNION ALL
SELECT R.id, R.parent FROM
RollupAccount AS R
JOIN
[Rollup] AS RP
ON R.parent = RP.ID
)
SELECT SUM(balance) AS Balance
FROM DetailAccount
JOIN
Rollup
ON DetailAccount.parent = [Rollup].id
OPTION (MAXRECURSION 1)
Msg 530, Level 16, State 1, Line 1
The statement terminated. The maximum recursion
1 has been exhausted before statement completion.
a
b
