Guest User

Untitled

a guest
Jan 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. ;WITH Combi (ID_ART, COLOR, COMBI, COMBI_CUT, NB_BAR, NB_CUTS, MAX_CUTS)
  2. AS
  3. ( SELECT C.ID_ART,
  4. C.COLOR,
  5. '-' + ID_COMBI_BAR_STR + '-',
  6. '-' + C.CUT_COMBI + '-',
  7. 1,
  8. C.NB_CUTS,
  9. ISNULL(MAXI.CUT_NUM,0)
  10. FROM #COMBI_BARRE C with(nolock)
  11. outer apply (select top 1 D.CUT_NUM
  12. from #DEBITS D
  13. where D.ID_ART = C.ID_ART
  14. and D.COLOR= C.COLOR
  15. order by D.NUM_OCC_DEB desc) MAXI
  16. WHERE C.FIRST_CUT = 1
  17. UNION ALL
  18. SELECT C.ID_ART,
  19. C.COLOR,
  20. Combi.COMBI + ID_COMBI_BAR_STR + '-',
  21. Combi.COMBI_CUT+ C.CUT_COMBI + '-',
  22. Combi.NB_BAR+ 1,
  23. Combi.NB_CUTS+ C.NB_CUTS,
  24. Combi.MAX_CUTS
  25. FROM #COMBI_BARRE C with(nolock)
  26. INNER JOIN Combi on C.ID_ART = Combi.ID_ART
  27. and C.COLOR= Combi.COLOR
  28. where C.FIRST_CUT > Combi.NB_BAR
  29. and Combi.NB_CUTS+ C.NB_CUTS<= Combi.MAX_CUTS
  30. and NOT EXISTS(select * from #DET_BAR D with(nolock)
  31. where D.ID_COMBI_BAR = C.ID_COMBI_BAR
  32. and PATINDEX(D.ID_CUT_STR, Combi.COMBI_CUT) > 0)
  33. 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)
  34. )
  35. select * from Combi
Add Comment
Please, Sign In to add comment