简体   繁体   English

AS400查询/ Excel ODBC联合错误

[英]AS400 Query/Excel ODBC Union Error

I'm having issues getting a query working in Excel for our AS400/DB2 system. 我在使用Excel为AS400 / DB2系统进行查询时遇到问题。

I'm trying to use two different tables with different info, but return an aisle/slot in the same column based upon a specific SKU/Customer ID(Storer). 我正在尝试使用具有不同信息的两个不同的表,但是根据特定的SKU /客户ID(Storer)返回同一列中的过道/槽。 I thought a UNION would work but I get an "SQL0802 - Data conversion or data mapping error" when trying to run the query. 我认为UNION可以工作,但在尝试运行查询时,我得到“SQL0802 - 数据转换或数据映射错误”。

Here's what I have right now: 这就是我现在所拥有的:

SELECT ADJTRAN.AJAISL AS AISLE, ADJTRAN.AJSLOT AS SLOT
FROM S216F06V.WDLSDATA.ADJTRAN ADJTRAN
WHERE (AJITEM=8011989 AND AJSTOR=581)
UNION
SELECT ILCATER.ILAISL AS AISLE, ILCATER.ILSLOT AS SLOT
FROM S216F06V.WDLSDATA.ILCATER ILCATER
WHERE (ILITEM=8011989 AND ILSTOR=581)

Any help would be appreciated. 任何帮助,将不胜感激。

EDIT: AJAISL, AJSLOT, ILAISL and ILSLOT are character fields with a length of 4. 编辑:AJAISL,AJSLOT,ILAISL和ILSLOT是长度为4的字符字段。

Guessing at the data found in the columns being selected, CAST() or CONVERT() is likely to help you. 猜测所选列中的数据, CAST()CONVERT()可能会对您有所帮助。

Try something like — 试试像 -

SELECT CAST( ADJTRAN.AJAISL AS VARCHAR(128) ) AS AISLE, 
       CAST( ADJTRAN.AJSLOT AS VARCHAR(128) ) AS SLOT
...
UNION
SELECT CAST( ILCATER.ILAISL AS VARCHAR(128) ) AS AISLE, 
       CAST( ILCATER.ILSLOT AS VARCHAR(128) ) AS SLOT` 
...

EDITED TO ADD 编辑添加

Given that all selected columns are the same data type, it's probably one of the tested columns that's at issue. 鉴于所有选定的列都是相同的数据类型,它可能是所讨论的测试列之一。

You're comparing what look like INTEGER s to values in AJITEM , AJSTOR , ILITEM , and ILSTOR -- but what types are these columns, and is all data strictly conformant to that type? 您将INTEGER的外观与AJITEMAJSTORILITEMILSTOR值进行比较 - 但这些列的类型是什么,并且所有数据都严格符合该类型?

One troubleshooting strategy is to try smaller versions of your query, and gradually add elements, until you find the error trigger. 一种故障排除策略是尝试较小版本的查询,并逐渐添加元素,直到找到错误触发器。 Here, I'd try each part of the UNION separately, at least, if not one element of the WHERE ... AND therein. 在这里,我会分别尝试UNION每个部分,至少,如果不是WHERE ... AND一个元素。

Sometime Excel have bugs... Can you try it: 有时候Excel有bug ...你能试试吗:

    select * from (
    SELECT ADJTRAN.AJAISL AS AISLE, ADJTRAN.AJSLOT AS SLOT
    FROM S216F06V.WDLSDATA.ADJTRAN ADJTRAN
    WHERE (AJITEM=8011989 AND AJSTOR=581)
    UNION
    SELECT ILCATER.ILAISL AS AISLE, ILCATER.ILSLOT AS SLOT
    FROM S216F06V.WDLSDATA.ILCATER ILCATER
    WHERE (ILITEM=8011989 AND ILSTOR=581)
    ) tmp

AJITEM and ILITEM are VARCHAR(20). AJITEM和ILITEM是VARCHAR(20)。 I was comparing it to an INT. 我把它与INT进行比较。 Fixed and the code below works with zero issues. 修复了以下代码,零问题。 My fault for not stating this in the original question and overlooking such a simple mistake. 我没有在原来的问题中陈述这个并且忽略了这么简单的错误。

SELECT ADJTRAN.AJAISL AS AISLE, ADJTRAN.AJSLOT AS SLOT
FROM S216F06V.WDLSDATA.ADJTRAN ADJTRAN
WHERE (AJITEM='8011989' AND AJSTOR=581)
UNION
SELECT ILCATER.ILAISL AS AISLE, ILCATER.ILSLOT AS SLOT
FROM S216F06V.WDLSDATA.ILCATER ILCATER
WHERE (ILITEM='8011989' AND ILSTOR=581)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM