I have the following table
PNLTable([PnlId],
[Line],
[TotalisationId],
[Designation],
[Totalisation],
ParentId).
I use the following query to get for each pnlid all children
;WITH CTE
AS
(
SELECT PNLId ,concat('/',cast(PNLId as nvarchar(MAX)) )as tree, PNLParentId
FROM [dbo].[DimPNL]
WHERE PNLParentId IS NULL
UNION ALL
SELECT T1.PNLId,concat( CTE.tree ,'/',cast(t1.PNLId as nvarchar(MAX))), T1.PNLParentId
FROM [dbo].[DimPNL] AS T1
INNER JOIN CTE
ON T1.PNLParentId = CTE.PNLId
)
SELECT *
FROM CTE
I used a stored procedure spGetResult which updates Totalisation with some constraints .
How can I combine between spGetResultstarting
and the query above in order to start updating recursively from the lowest children to the high level (roots)?