CTE 를 이용한 BOM 전개
WITH BOM_CTE(P_ITEM_CD, C_ITEM_CD, LEVEL) AS ( SELECT T.P_ITEM_CD, T.C_ITEM_CD, 1 AS LEVEL FROM bba020t_2 T WHERE T.P_ITEM_CD in ('HU3723-V') UNION ALL SELECT C.P_ITEM_CD, C.C_ITEM_CD, LEVEL+1 FROM bba020t_2 C INNER JOIN BOM_CTE P ON C.P_ITEM_CD = P.C_ITEM_CD --WHERE C.P_ITEM_CD in ('HU3723-V') ) SELECT P_ITEM_CD, C_ITEM_CD, MAX(LEVEL) AS LEVEL FROM BOM_CTE --WHERE P_ITEM_CD in ('HU3723-V') GROU..
DataBase/SQL Server
2008. 4. 1. 10:12