跳至主要內容

库存转储报表(仓库版)

五六零网校小于 1 分钟

代码示例

SELECT T0.[DocNum], T1.[ItemCode], T2.[FrgnName], T2.[ItemName], T1.[Dscription]
	, T4.[SlpName], T1.[Quantity], T1.[OpenQty], T2.[OnHand], T1.[FromWhsCod] AS 从仓库
	, T1.[WhsCode] AS 到仓库, TS.[BatchNum] AS 批次号, TS.[Quantity] AS 批次转出数量, TS.[BinCode] AS 库位号, TS.[Quantity] AS 库位转入数量
FROM OWTR T0
	INNER JOIN WTR1 T1 ON T0.[DocEntry] = T1.[DocEntry]
	INNER JOIN OITM T2 ON T1.[ItemCode] = T2.[ItemCode]
	INNER JOIN OITB T3 ON T2.[ItmsGrpCod] = T3.[ItmsGrpCod]
	LEFT JOIN OSLP T4 ON T0.[SlpCode] = T4.[SlpCode]
	LEFT JOIN (
		SELECT T2.[BinCode], T1.[Quantity], T1.[SnBMDAbs], T4.[BatchNum], T0.[LocCode]
			, T0.[DocEntry], T0.[ItemCode], T0.[BaseType]
		FROM OILM T0
			INNER JOIN OBTL T1 ON T0.[MessageID] = T1.[MessageID]
			INNER JOIN OBIN T2 ON T1.[BinAbs] = T2.[AbsEntry]
			INNER JOIN OBTN T3 ON T3.ABSENTRY = T1.[SnBMDAbs]
			INNER JOIN IBT1 T4
			ON T4.[BatchNum] = T3.[DistNumber]
				AND T4.itemcode = t0.itemcode
				AND T4.[WhsCode] = T0.[LocCode]  				
                                                   AND T4.[BaseEntry]= T0.[DocEntry]
	) TS
	ON Ts.[DocEntry] = t0.docentry
		AND Ts.[ItemCode] = t1.itemcode
		AND Ts.[LocCode] = t1.whscode
		AND TS.[BaseType] = t0.objtype 

ORDER BY T0.[DocNum] DESC