Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;WITH Combi (ID_ART, COLOR, COMBI, COMBI_CUT, NB_BAR, NB_CUTS, MAX_CUTS)
- AS
- ( SELECT C.ID_ART,
- C.COLOR,
- '-' + ID_COMBI_BAR_STR + '-',
- '-' + C.CUT_COMBI + '-',
- 1,
- C.NB_CUTS,
- ISNULL(MAXI.CUT_NUM,0)
- FROM #COMBI_BARRE C with(nolock)
- outer apply (select top 1 D.CUT_NUM
- from #DEBITS D
- where D.ID_ART = C.ID_ART
- and D.COLOR= C.COLOR
- order by D.NUM_OCC_DEB desc) MAXI
- WHERE C.FIRST_CUT = 1
- UNION ALL
- SELECT C.ID_ART,
- C.COLOR,
- Combi.COMBI + ID_COMBI_BAR_STR + '-',
- Combi.COMBI_CUT+ C.CUT_COMBI + '-',
- Combi.NB_BAR+ 1,
- Combi.NB_CUTS+ C.NB_CUTS,
- Combi.MAX_CUTS
- FROM #COMBI_BARRE C with(nolock)
- INNER JOIN Combi on C.ID_ART = Combi.ID_ART
- and C.COLOR= Combi.COLOR
- where C.FIRST_CUT > Combi.NB_BAR
- and Combi.NB_CUTS+ C.NB_CUTS<= Combi.MAX_CUTS
- and NOT EXISTS(select * from #DET_BAR D with(nolock)
- where D.ID_COMBI_BAR = C.ID_COMBI_BAR
- and PATINDEX(D.ID_CUT_STR, Combi.COMBI_CUT) > 0)
- and NOT EXISTS(select top 1 * from Combi Combi2 where Combi2.ID_ART = C.ID_ART and Combi2.COLOR = C.COLOR and Combi2.NB_CUTS = Combi2.MAX_CUTS)
- )
- select * from Combi
Add Comment
Please, Sign In to add comment