Results 1 to 3 of 3

Thread: Error SQL query

  1. #1
    Join Date
    Jul 2010
    Posts
    1

    Unanswered: Error SQL query

    Hi all!

    I have a problem with a SQL query, can't seem to get it working.

    description:
    I have 4 tables in a DB2 environment, accessing from a external environment (Notrix) using SQL, I want to link these tables based on the Column 'IDNumber'.
    From the first table I want to make a selection based on several codes in the column 'CodeNumber', codenumber=002 and codenumber=004. For all rows that match the codenumber in table 1 collect information from the other 3 tables (based on IDNumber).

    First I join the 4 tables, based on the IDNumber column, then make the selection

    Here is my SQL query for the selection:
    SELECT QQ.Table1.IDNumber, QQ.Table1.C1, QQ.Table1.C2, QQ.Table1.CodeNumber, QQ.Table2.CodeNumber,QQ.Table2.IDNumber, QQ.Table2.C3, QQ.Table3.CodeNumber, QQ.Table3.IDNumber, QQ.Table2.C4, QQ.Table4.IDNumber, QQ.Table4.CodeNumber, QQ.Table2.C5
    FROM
    QQ.Table1,
    QQ.Table2,
    QQ.Table3,
    QQ.Table4
    WHERE
    QQ.Table1.IDNumber = QQ.Table2.IDNumber AND
    QQ.Table1.IDNumber = QQ.Tabel3.IDNumber AND
    QQ.Table1.IDNumber = QQ.Tabel4.IDNumber AND
    (QQ.Table1.CodeNumber = 002 OR QQ.Table1.CodeNumber = 002)

    I get the following errormessage:
    SQL0401N The data types of the operands for the operation "" are not compatible. SQLSTATE=42818

    Hope someone can help me.

    Thanks!

    Michel
    Last edited by michelvb; 07-30-10 at 07:13.

  2. #2
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963

    Question The manuals are for whom

    Quote Originally Posted by michelvb View Post
    Hi all!

    I have a problem with a SQL query, can't seem to get it working.

    description:
    I have 4 tables in a DB2 environment, accessing from a external environment (Notrix) using SQL, I want to link these tables based on the Column 'IDNumber'.
    From the first table I want to make a selection based on several codes in the column 'CodeNumber', codenumber=002 and codenumber=004. For all rows that match the codenumber in table 1 collect information from the other 3 tables (based on IDNumber).

    First I join the 4 tables, based on the IDNumber column, then make the selection

    Here is my SQL query for the selection:
    SELECT QQ.Table1.IDNumber, QQ.Table1.C1, QQ.Table1.C2, QQ.Table1.CodeNumber, QQ.Table2.CodeNumber,QQ.Table2.IDNumber, QQ.Table2.C3, QQ.Table3.CodeNumber, QQ.Table3.IDNumber, QQ.Table2.C4, QQ.Table4.IDNumber, QQ.Table4.CodeNumber, QQ.Table2.C5
    FROM
    QQ.Table1,
    QQ.Table2,
    QQ.Table3,
    QQ.Table4
    WHERE
    QQ.Table1.IDNumber = QQ.Table2.IDNumber AND
    QQ.Table1.IDNumber = QQ.Tabel3.IDNumber AND
    QQ.Table1.IDNumber = QQ.Tabel4.IDNumber AND
    (QQ.Table1.CodeNumber = 002 OR QQ.Table1.CodeNumber = 002)

    I get the following errormessage:
    SQL0401N The data types of the operands for the operation "" are not compatible. SQLSTATE=42818

    Hope someone can help me.

    Thanks!

    Michel
    Something like following is much closer to truth:

    Code:
    SELECT 
    Table1.IDNumber, Table1.C1, Table1.C2, Table1.CodeNumber, 
    Table2.CodeNumber,Table2.IDNumber, Table2.C3, Table3.CodeNumber, 
    Table3.IDNumber, Table2.C4, Table4.IDNumber, Table4.CodeNumber, 
    Table2.C5
    FROM
    QQ.Table1,
    QQ.Table2,
    QQ.Table3,
    QQ.Table4
    WHERE 
    Table1.IDNumber = Table2.IDNumber AND 
    Table1.IDNumber = Tabel3.IDNumber AND
    Table1.IDNumber = Tabel4.IDNumber AND 
    Table1.CodeNumber = '002'
    Lenny

  3. #3
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    I get the following errormessage:
    SQL0401N The data types of the operands for the operation "" are not compatible. SQLSTATE=42818
    If the received error message is exactly same as above(especially operation ""),
    check and compare data types of columns used in your query.

    For example:
    1) Compare data types of QQ.Table1.IDNumber, QQ.Table2.IDNumber, QQ.Table3.IDNumber and QQ.Table4.IDNumber
    2) Is data type of QQ.Table1.CodeNumber numeric?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •