1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| WITH src
AS ( SELECT DISTINCT
M.GL_CATEGORY_CD
, M.MATERIAL_ID
, M.MATERIAL_LONG_CD
, M.MATERIAL_CAT12_CD
, M.MATERIAL_CAT13_CD
, M.MATERIAL_CAT11_CD
, M.MATERIAL_CAT1_CD
, A.EAN_CD
, V.EAN_CD AS CODE_EAN_UC
, A.EAN_TYPE_CD
, A.PCB_CD
, M.MATERIAL_TYPE_CD
FROM MATERIAL M
INNER JOIN
ARTICLES_EAN A
ON M.MATERIAL_SID = A.MATERIAL_SID
INNER JOIN
ARTICLES_EAN V
ON M.MATERIAL_SID = V.MATERIAL_SID
WHERE M.MATERIAL_CAT12_CD <>'ZZ'
AND A.EAN_TYPE_CD = 'UC'
AND V.EAN_TYPE_CD = 'UC'
AND A.EAN_CD > V.EAN_CD
)
SELECT GL_CATEGORY_CD
, MATERIAL_ID
, MATERIAL_LONG_CD
, MATERIAL_CAT12_CD
, MATERIAL_CAT13_CD
, MATERIAL_CAT11_CD
, MATERIAL_CAT1_CD
, EAN_CD
, EAN_TYPE_CD
, PCB_CD
, MATERIAL_TYPE_CD
FROM src
UNION
SELECT GL_CATEGORY_CD
, MATERIAL_ID
, MATERIAL_LONG_CD
, MATERIAL_CAT12_CD
, MATERIAL_CAT13_CD
, MATERIAL_CAT11_CD
, MATERIAL_CAT1_CD
, CODE_EAN_UC AS EAN_CD
, EAN_TYPE_CD
, PCB_CD
, MATERIAL_TYPE_CD
FROM src
; |
Partager