I am writing a report to pull metal spot prices based on the promise date of shipments. It uses the 60 Day midwest (MW) average. So for a shipment promised in March the MW average from January is used. The table is user defined and there are some issues that keep me from just pulling the field like normal (loong story).
So I wrote a query to compare the column label in the database ([MONTH] [YEAR]) to the month and year of the promise date and return the correct MW average. It runs properly in Oracle's SQL Developer but in Crystal it runs incorrectly, returning the same month's MW average (or doesn't run at all). It is below for reference. (I know it's a bit clunky)
select ap.invoice_Date indate,
ap.invoice_no as invno,
ap.vendor_id,
apd.po_detail_id as podid,
por.promise_date as pd,
dat.parent_id as vendid,
dat.ud_cols_id as cols,
col.col_label label,
dat.cuser as ingot
from ud_data dat
inner join ud_cols col
on dat.ud_cols_id = col.id
inner join apinvoice ap
on ap.vendor_id = dat.parent_id
inner join apinvoice_detail apd
on ap.id = apd.apinvoice_id
inner join po_detail pod
on apd.po_detail_id = pod.id
inner join po_releases por
on pod.id = por.po_detail_id
where trim(TO_CHAR(add_months(por.promise_date, -2), 'MONTH'))= upper(substr(COL.col_label, 1, length(col_label)-5))
and substr(por.promise_date, -2, 2) = substr(col.col_label, -2, 2)
and ud_cols_id in (94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 146)
order by ap.invoice_Date
I'm thinking it has something to do with the dates and formatting but I broke those out and the comparisons match up. I tried every combo of linking I could (but stuck with left outer joins, inner join made the report return blank). Browsing the field data there is nothing either.
Any ideas at all are appreciated. I'm at a loss..