SELECT T0.[JrnlMemo] AS 收货类型, T0.[DocNum], T0.[DocDate], T1.[ItemCode], T1.[Dscription]
	, T2.[FrgnName], T1.[UseBaseUn], T1.[Quantity], T1.[Price], T1.[LineTotal]
	, TS.[BatchNum] AS 批次号, TS.[Quantity] AS 批次数量, TS.[BinCode] AS 库位号, TS.[Quantity] AS 库位发出数量, T2.[OnHand]
	, T5.[AvgPrice]
FROM OIGE T0
	INNER JOIN IGE1 T1 ON T0.[DocEntry] = T1.[DocEntry]
	INNER JOIN OITM T2 ON T1.[ItemCode] = T2.[ItemCode]
	INNER JOIN OITB T3 ON T2.[ItmsGrpCod] = T3.[ItmsGrpCod]
	INNER JOIN OSLP T4 ON T0.[SlpCode] = T4.[SlpCode]
	INNER JOIN OITW T5
	ON T5.itemcode = t2.itemcode
		AND t5.whscode = t1.whscode
	LEFT JOIN (
		SELECT T2.[BinCode], T1.[Quantity], T1.[SnBMDAbs], T4.[BatchNum], T0.[LocCode]
			, T0.[DocEntry], T0.[ItemCode], T0.[TransType]
		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.[TransType] = t0.objtype

WHERE
----物料编码 大于等于 A    AND  物料编码小于等于 B
 (T1.[ItemCode] LIKE '%%[%0]%%' or '[%0]'='') 
----物料名称
AND ( T2.[FrgnName]LIKE '%%[%2]%%' or '[%2]'='') 
----单据日期
AND  ( T0.[taxDate] LIKE '%%[%4]%%'  or '[%4]'='')  
----单据状态
AND   ( T0.[DocStatus] = '[%6]' or '[%6]'='') 
----物料组
AND (T3.[ItmsGrpNam]  LIKE '%%[%7]%%' or '[%7]'='') 
----单据编号
AND (T0.[DOCNUM]LIKE '%%[%17]%%'  or [%17]='')  
AND T1.[BaseType]='-1'
ORDER BY T0.[DocNum] DESC

发表回复

后才能评论