I am attempting to write some SQL that will be used to select data for a report. The data is coming from JD Edwards, using the DB2 database on AS/400.
I have written the following SQL query:
SELECT F3112.WLDOCO AS DOC_NO,
F3112.WLDCTO AS DOC_TYPE,
F3112.WLCTS4 AS UDL_AMOUNT,
F3112.WLCTS9 AS UDL_HOURS,
F3112.WLLABA AS RUN_LABOR_ACT,
F3112.WLMACA AS RUN_MACHINE_ACT,
F0911.GLSBL AS OBJ_ACCT,
F0911.GLAA AS GL_AMOUNT,
F0911.GLU AS GL_UNITS,
F4801.WASRST AS WO_STATUS
FROM PROD2DTA.F3112 F3112
INNER JOIN PROD2DTA.F0911 F0911
ON F3112.WLDOCO = CAST(F0911.GLSBL AS INTEGER)
INNER JOIN PROD2DTA.F4801 F4801
ON F3112.WLDOCO = F4801.WADOCO
WHERE F0911.GLOBJ = '6855'
AND F4801.WASRST BETWEEN '30' AND '95'
Where:
F3112 - Work Order Routing
F4801 - Work Order Master
- WASRST (WO status code) is a string of length 2. It's a set of enumerated values.
F0911 - Account Ledger
- GLSBL (G/L subledger) may contain the document number from Work Order Routing (F3112.WLDOCO). The important thing to note is that GLSBL is a string, length 8 and the values are left padded with zeros. F3112.WLDOCO is a numeric value with length 8 (no padding). This is why I have the CAST in the JOIN clause.
- GLOBJ (Object account) is a string of length 6. I do not know if there is any padding.
This query will not run. It gives me a somewhat cryptic "data conversion or mapping error". I haven't been able to figure out what the offending SQL is.
Now here's the weird part. If I modify this query slighty to join F3112 with ONLY F4801 OR F0911, either form of the query works. I just can't get them to work together as one query (Is there a clue here?).
So, to illustrate:
SELECT F3112.WLDOCO AS DOC_NO,
F3112.WLDCTO AS DOC_TYPE,
F3112.WLCTS4 AS UDL_AMOUNT,
F3112.WLCTS9 AS UDL_HOURS,
F3112.WLLABA AS RUN_LABOR_ACT,
F3112.WLMACA AS RUN_MACHINE_ACT,
F0911.GLSBL AS OBJ_ACCT,
F0911.GLAA AS GL_AMOUNT,
F0911.GLU AS GL_UNITS
FROM PROD2DTA.F3112 F3112
INNER JOIN PROD2DTA.F0911 F0911
ON F3112.WLDOCO = CAST(F0911.GLSBL AS INTEGER)
WHERE F0911.GLOBJ = '6855'
and
SELECT F3112.WLDOCO AS DOC_NO,
F3112.WLDCTO AS DOC_TYPE,
F3112.WLCTS4 AS UDL_AMOUNT,
F3112.WLCTS9 AS UDL_HOURS,
F3112.WLLABA AS RUN_LABOR_ACT,
F3112.WLMACA AS RUN_MACHINE_ACT,
F4801.WASRST AS WO_STATUS
FROM PROD2DTA.F3112 F3112
INNER JOIN PROD2DTA.F4801 F4801
ON F3112.WLDOCO = F4801.WADOCO
WHERE F4801.WASRST BETWEEN '30' AND '95'
These both work just fine.