下面的SELECT
语句来自一个存储过程,该存储过程完美地运行了,没有两个日期比较列AFIOTD
和CustomerOTD
。 (如果1
,则返回[startdate] <= [enddate]
,否则返回0
。)启用列时,我的调用代码会引发溢出错误。
该调用来自MS Access 2016
VBA模块,并且此SP在MS SQL 2016
上运行。
存储过程将填充DAO记录集。
SELECT COL.COMMODITY_CODE, Rec.INVOICE_ID, Rec.INVOICE_DATE, Rec.CUSTOMER_ID, Cust.NAME, Cust.ADDR_1, Cust.CITY, Cust.STATE, COL.PART_ID, Bustout.PART_NUMBER,
Bustout.AUX, Rec_Line.AMOUNT, ShipLine.SHIPPED_QTY, Shipper.PACKLIST_ID, COL.PROMISE_DATE, COL.DESIRED_SHIP_DATE,
CASE
WHEN DATEDIFF(day, CAST(Rec.INVOICE_ID AS datetime), CAST(COL.PROMISE_DATE AS datetime)) >= 0
THEN CAST(1 AS int)
ELSE CAST(0 AS int)
END AS AFIOTD,
CASE
WHEN DATEDIFF(day, CAST(Rec.INVOICE_ID AS datetime), CAST(COL.DESIRED_SHIP_DATE AS datetime)) >= 0
THEN CAST(1 AS int)
ELSE CAST(0 AS int)
END AS CustomerOTD
FROM dbo.AFI_PARTS_BUSTOUT AS Bustout RIGHT OUTER JOIN
AFIRALSRV06.AFI.dbo.SHIPPER_LINE AS ShipLine RIGHT OUTER JOIN
AFIRALSRV06.AFI.dbo.SHIPPER AS Shipper ON ShipLine.PACKLIST_ID = Shipper.PACKLIST_ID RIGHT OUTER JOIN
AFIRALSRV06.AFI.dbo.RECEIVABLE_LINE AS Rec_Line ON Shipper.INVOICE_ID = Rec_Line.INVOICE_ID AND Shipper.PACKLIST_ID = Rec_Line.PACKLIST_ID LEFT OUTER JOIN
AFIRALSRV06.AFI.dbo.CUST_ORDER_LINE AS COL ON Rec_Line.CUST_ORDER_ID = COL.CUST_ORDER_ID AND Rec_Line.CUST_ORDER_LINE_NO = COL.LINE_NO ON
Bustout.PART_NUMBER = COL.PART_ID RIGHT OUTER JOIN
AFIRALSRV06.AFI.dbo.RECEIVABLE AS Rec INNER JOIN
AFIRALSRV06.AFI.dbo.CUSTOMER AS Cust ON Rec.CUSTOMER_ID = Cust.ID ON Rec_Line.INVOICE_ID = Rec.INVOICE_ID
WHERE (Rec.INVOICE_DATE >= CONVERT(DATETIME, @InvoiceDateStart, 102) AND Rec.INVOICE_DATE <= CONVERT(DATETIME, @InvoiceDateEnd, 102))
AND (NOT (Shipper.PACKLIST_ID IS NULL))