I think this is an issue of CAST correctly on q but not sure how. Quantity is defined as (numeric(24, 5), not null) Thank you for your help.
with all_item_counts as
(
select
ParentId, Id, Quantity as q, 0 as level
from
dbo.MBOM
union all
select
all_item_counts. ParentId, dbo.MBOM.Id, Quantity * q, level + 1
from
all_item_counts
join
dbo.MBOM on dbo.MBOM. ParentId = all_item_counts.Id
)
select
ParentId, Id, sum(q)
from
all_item_counts
group by
ParentId, Id
I get this error:
Msg 240, Level 16, State 1, Line 1
Types don't match between the anchor and the recursive part in column "q" of recursive query "all_item_counts".