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')
GROUP BY P_ITEM_CD, C_ITEM_CD
ORDER BY P_ITEM_CD ASC
OPTION(MAXRECURSION 3)
SQL Server 2005 데이터베이스 복원(bak 파일) (0) | 2008.04.02 |
---|---|
SQL Database documentation script (0) | 2008.04.01 |
SQL Server 2005 데이타베이스 복원 (0) | 2008.04.01 |
DB에 있는 table사용량 체크 (0) | 2008.04.01 |
시스템의 모든 테이블 정보 (0) | 2008.04.01 |