跳至主要內容

物料按BOM合计成本(包含资源)

五六零网校大约 1 分钟

代码示例

SELECT T2.[ItemCode] AS '主件编码', T2.[ItemName] AS '主件描述', T0.[ItemCode] AS '子件编码', T0.[ItemName] AS '子件描述', T1.[Quantity] AS '数量'
	, T4.[Price] AS '单价', T1.[Quantity] * T4.[Price] AS '行总计', T0.[BuyUnitMsr] AS '计量单位名称', T1.[U_T003] AS '费用金额'
	, T1.[U_T004] AS '费用名称', T1.[Comment] AS '备注', NULL AS '----总计部分----'
	, CASE ROW_NUMBER() OVER (PARTITION BY T2.[ItemCode] ORDER BY TA.RG)
		WHEN 1 THEN TA.RG
		ELSE NULL
	END AS '总人工'
	, CASE ROW_NUMBER() OVER (PARTITION BY T2.[ItemCode] ORDER BY TS.WG)
		WHEN 1 THEN TS.WG
		ELSE NULL
	END AS '总物料成本'

FROM OITM T0
	INNER JOIN ITT1 T1 ON T0.[ItemCode] = T1.[Code]
	INNER JOIN OITM T2 ON T1.[Father] = T2.[ItemCode]
	INNER JOIN ITM1 T4
	ON T0.[ItemCode] = T4.[ItemCode]
		AND T4.[PriceList] = '5'
	LEFT JOIN (
		SELECT T0.[Father]
			, SUM(ISNULL(T0.[U_T003], 0) + ISNULL(T1.ZY, 0)) AS 'RG'
		FROM ITT1 T0
			LEFT JOIN (
				SELECT T0.[Father], T0.code, T0.[Quantity] * T0.[Price] AS 'ZY'
				FROM ITT1 T0
				WHERE T0.[Type] = '290'
			) T1
			ON T1.father = t0.father
				AND T1.CODE = T0.CODE
		GROUP BY T0.[Father]
	) TA
	ON TA.[Father] = T2.[ItemCode]
	LEFT JOIN (
		SELECT T0.[Father], SUM(T0.[Quantity] * T4.[Price]) AS 'WG'
		FROM ITT1 T0
			INNER JOIN ITM1 T4
			ON T0.[Code] = T4.[ItemCode]
				AND T4.[PriceList] = '5'
		GROUP BY T0.[Father]
	) TS
	ON TS.[Father] = T2.[ItemCode]
WHERE T2.[ItemCode] LIKE '15%%'
	AND T2.[ItemName] LIKE '%%[%0]%%'
ORDER BY T2.[ItemCode] DESC, T1.[ChildNum]