If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Error SQL query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-30-10, 06:04
michelvb michelvb is offline
Registered User
 
Join Date: Jul 2010
Posts: 1
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 06:13.
Reply With Quote
  #2 (permalink)  
Old 07-30-10, 10:04
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
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
Reply With Quote
  #3 (permalink)  
Old 07-31-10, 07:57
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
Quote:
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?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On