update Wit_Pro_Tasks
set Task_PCT_COMP =
( select
(case when sum (Task_Work) is null then 0
when sum (Task_Work) = 0 then 0
else ceiling( round(sum(cast (Task_Work as bigint) * Task_PCT_COMP ) / sum (Task_Work) ,0))
end)
from Wit_Pro_Tasks a where a.isleaf = 1 and a.path like Wit_Pro_Tasks.path + '.%')
where isleaf = 0
set Task_PCT_COMP =
( select
(case when sum (Task_Work) is null then 0
when sum (Task_Work) = 0 then 0
else ceiling( round(sum(cast (Task_Work as bigint) * Task_PCT_COMP ) / sum (Task_Work) ,0))
end)
from Wit_Pro_Tasks a where a.isleaf = 1 and a.path like Wit_Pro_Tasks.path + '.%')
where isleaf = 0