I posted a question last week about this and did get an answer that worked. but I need to find tune my query. I have a recursive query that gets my BOM however it is not indented. I see several items on lvl 0,1,2 however it does not put the levels in indented form. My query results show:
MainAssy SubAssy t_item t_qana lvl YearExp
4586-2 3761-4 A022202 1.69 2 1753
4586-2 4564 A023502 1.75 2 1753
4586-2 4586 3761-4 1 1 1753
4586-2 4586 4564 1 1 1753
4586-2 4586 4586 0 0 1753
4586-2 4586 4587 1 1 1753
4586-2 4587 A025602 2.75 2 1753
4586-2 64889 64889 1 0 1753
4586-2 64889 A021702 1.3 1 1753
The "A0" number are level 2 but A025602 in part 4587 and A023502 is in part 4564. This result does not indicate that.
Is there any way to rewrite the script so that it shows the levels in correct order meaning main, assy, sub assy, item etc.
Here is the script I am using now:
with BOMCTE AS (
SELECT t_mitm as MainAssy, t_sitm as SubAssy, t_sitm as t_item, t_qana, 0 AS lvl, year(t_exdt) as 'YearExp'
FROM ttibom010100
where year(t_exdt) = 1753
UNION ALL
SELECT usr.MainAssy, mgr.t_mitm, mgr.t_sitm, mgr.t_qana, usr.lvl +1 AS lvl, YearExp
FROM BOMCTE AS usr
INNER JOIN ttibom010100 AS mgr
ON usr.t_item = mgr.t_mitm
where year(t_exdt) = 1753
)
SELECT distinct *
FROM BOMCTE AS u
where MainAssy = '4586-2'
Thanks