I'm writing a query to do some stuff. But its not working the way I want it to:
select CORR_ID from TABLE1
where CORR_ID not in (select id from TABLE2)
The problem is, TABLE2.id is a long, while TABLE1.CORR_ID is a string.
So how can I make it work?
PS: I'm using IBM UDB.
DB2 CAST is a function available in DB2 that is used for explicit conversion of the data type of a particular value to another datatype.
-420 THE VALUE OF A STRING ARGUMENT WAS NOT ACCEPTABLE TO THE function-name FUNCTION.
DB2 varchar ordinarily holds 1 byte for every character and 2 additional bytes for the length data. It is prescribed to utilize varchar as the information type when segments have variable length and the real information is path not exactly the given limit.
A big integer is a binary integer with a precision of 63 bits. The range of big integers is -9223372036854775808 to +9223372036854775807.
Okay, I found a method:
select CORR_ID from TABLE1 where CORR_ID not in
(select CAST( CAST(id AS CHAR(50)) AS VARCHAR(50) ) from TABLE2)
This is pretty intriguing: You can't cast a BIGINT to VARCHAR, but:
this is ridiculous!
DB2 allows a VARCHAR and CHAR column to be compared without additional casting, so all you really need to do is cast the number.
SELECT corr_id FROM table1 WHERE corr_id NOT IN (SELECT CHAR( id ) FROM table2 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With