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 > Character to Integer conversion in where clause

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-13-09, 06:01
nkamalkishore nkamalkishore is offline
Registered User
 
Join Date: Nov 2009
Posts: 3
Character to Integer conversion in where clause

Hello All,

How to convert a character column to integer in the where clause.

Example:

select * from tabname where int(colname) between 1 and 50;

In the above example the int(colname) is not working but it works if specified as select int(colname) from tabname.

Thanks in advance
Kamal K Nelli
Reply With Quote
  #2 (permalink)  
Old 11-13-09, 06:55
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
if this works : select int(colname) from tabname
then it will surely work for : where int(colname) between 1 and 50

which db2 version you are using ? whats the error code ?
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #3 (permalink)  
Old 11-13-09, 06:57
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
What is the meaning of "not working"?

Did you got error messages?
or, the result was different from what you expected?

What DB2 version/release?
What platform(OS) are you using?
Reply With Quote
  #4 (permalink)  
Old 11-13-09, 19:42
DBFinder DBFinder is offline
Registered User
 
Join Date: Sep 2008
Location: Toronto,Canada
Posts: 606
Quote:
Originally Posted by nkamalkishore View Post
In the above example the int(colname) is not working but it works if specified as select int(colname) from tabname.
It works on my system DB2 V9.5.0 on Win-XP

Quote:
C:\Program Files\IBM\SQLLIB\BIN>db2 select name,age from tst

NAME AGE
---------- ---
Sarbjit 16
Surjit 11
Aman 05
Gauri 25
Harsh 52

5 record(s) selected.


C:\Program Files\IBM\SQLLIB\BIN>db2 select name,age from tst where int(age) between 10 and 30

NAME AGE
---------- ---
Sarbjit 16
Surjit 11
Gauri 25

3 record(s) selected.


C:\Program Files\IBM\SQLLIB\BIN>db2level
DB21085I Instance "DB2" uses "32" bits and DB2 code release "SQL09050" with
level identifier "03010107".
Informational tokens are "DB2 v9.5.0.808", "s071001", "NT3295", and Fix Pack
"0".
Product is installed at "C:\PROGRA~1\IBM\SQLLIB" with DB2 Copy Name "DB2COPY1".
Let me know if you need me test on different version. Logically it should work.

DBFinder
Reply With Quote
  #5 (permalink)  
Old 11-15-09, 06:18
sawangupta sawangupta is offline
Registered User
 
Join Date: Nov 2009
Location: Bangalore
Posts: 25
You can also achieve the same using CAST operator

CAST specification - IBM DB2 9.7 for Linux, UNIX, and Windows

Regards,
Sawan Gupta
Reply With Quote
  #6 (permalink)  
Old 11-15-09, 11:03
DB2Plus DB2Plus is offline
Registered User
 
Join Date: Jul 2009
Posts: 150
It means result table is empty on select, but select shown some integers in between.

But how I understand he shown to us part of predicate....

Kara.
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