跳至主要內容

采购收货单(按批次分行显示)

五六零网校小于 1 分钟

使用说明:采购收货单有批次的,在对应物料行下分行显示

代码示例

WITH BATCH (docentry, CardName, DocDate, itemcode, name, quantity, LineNum) AS (
		SELECT T0.[DocEntry], T0.[CardName], T0.[DocDate], T1.[ItemCode] AS '物料编码', T1.[Dscription] AS '物料描述or批号'
			, T1.[Quantity] AS '数量', T1.[LineNum]
		FROM OPDN T0
			INNER JOIN PDN1 T1 ON T0.[DocEntry] = T1.[DocEntry]
		UNION ALL
		SELECT T0.[ApplyEntry], T0.[CardName], T0.[DocDate], T0.[ItemCode]
			, N'----    ' + T2.[DistNumber], T1.[Quantity], 10000
		FROM OITL T0
			INNER JOIN ITL1 T1 ON T0.[LogEntry] = T1.[LogEntry]
			INNER JOIN OBTN T2
			ON T2.[SysNumber] = T1.[SysNumber]
				AND T2.[ItemCode] = T1.[ItemCode]
		WHERE T0.[ApplyType] = '20'
	)
SELECT T0.[DocEntry] AS '单据编号', T0.[CardName] AS '客户名称', T0.[DocDate] AS '过账日期', T0.[ItemCode] AS '物料编码', T0.[name] AS '物料描述or批号'
	, T0.[Quantity] AS '数量'
FROM BATCH T0
WHERE T0.[DocDate] >='[%0]' AND T0.[DocDate] <='[%1]'
ORDER BY T0.[DocEntry] DESC, T0.[ItemCode], T0.[LineNum]

效果图

销售
销售