I've discovered this both in a dataset and directly in Excel using same query. If I force a DB2 field into a DATE and then subtract one from the other - it's correct for about month or two before the result goes haywire and starts showing very incorrect answers. Anyone run into this?
I'm finding using our DB2 V7 on AS400 (running a BPCS ERP system from circa 1998) isn't playing nicely with SQL Server. But, I'm getting around the quirks slowly but surely.
If anyone has a better approach to the DATES - I'm all ears (eyes). I've tried various approaches and all fail so far.
- DB2 V7R1 - AS400
- SQL Server 2008 R2
Specific piece of the query:
((DATE(SUBSTR(SIL.ILSDTE, 1, 4)||'-'||SUBSTR(SIL.ILSDTE,5,2)||'-'||SUBSTR(SIL.ILSDTE,7,2))) - (DATE(SUBSTR(ECL.LSDTE, 1, 4)||'-'||SUBSTR(ECL.LSDTE,5,2)||'-'||SUBSTR(ECL.LSDTE,7,2)))) AS "ShipDays"
Entire Query (although the above is only important bit):
SELECT ECL.LORD AS "Sales Order", ECL.LLINE AS "Sales Line", ECL.LPROD AS Item, IIM.IDESC AS "Item Description", IIM.IITYP AS "Item Type", ECL.LCLAS AS "Item Class", ECL.LQORD AS "Qty Ordered", ECL.LQSHP AS "Qty Shipped", SIL.ILNET AS "Net Price/Trans/Stocking", SIL.ILREV AS "G/L Revenue Amt", ECL.LUM AS "Unit of Measure", DATE(SUBSTR(ECL.LRDTE, 1, 4)||'-'||SUBSTR(ECL.LRDTE,5,2)||'-'||SUBSTR(ECL.LRDTE,7,2)) AS "Order Date", DATE(SUBSTR(ECL.LSDTE, 1, 4)||'-'||SUBSTR(ECL.LSDTE,5,2)||'-'||SUBSTR(ECL.LSDTE,7,2)) AS "Request Date", ECL.LCUST AS "Customer Number", DATE(SUBSTR(ECL.LUDTE1, 1, 4)||'-'||SUBSTR(ECL.LUDTE1,5,2)||'-'||SUBSTR(ECL.LUDTE1,7,2)) AS "Lead Date", DATE(SUBSTR(ECL.LUDTE2, 1, 4)||'-'||SUBSTR(ECL.LUDTE2,5,2)||'-'||SUBSTR(ECL.LUDTE2,7,2)) AS "Est Ship Date", ECL.LRES2 AS "Late Code", DATE(SUBSTR(SIL.ILSDTE, 1, 4)||'-'||SUBSTR(SIL.ILSDTE,5,2)||'-'||SUBSTR(SIL.ILSDTE,7,2)) AS "Shipped Date" FROM BPCSFILE64.IIM IIM, BPCSFILE64.ECL ECL, BPCSFILE64.SIL SIL WHERE IIM.IPROD = ECL.LPROD AND ECL.LORD = SIL.ILORD AND ECL.LLINE = SIL.ILSEQ AND (SIL.ILSDTE >= ?) AND (SIL.ILSDTE <= ?) AND (ECL.LQORD > 0) AND (ECL.CLBTYP = 1)