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 > Informix > Char to Int conversion

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-01-04, 02:45
insix insix is offline
Registered User
 
Join Date: Jan 2004
Posts: 2
Char to Int conversion

Is there any function in informix sql that converts char to int for use with relational operators (>, <, <= etc.)
I am using a char type column that contains numeric data, and need to compare data in this column with specific numbers. The query does not return correct results when I use the following where clause:
...where card_no[1,9] < "40110018"; In this case the query returns rows that contain 40110019 and greater numbers, even 9 and 10 digit numbers.

Where as if I use ...where card_no[1,9] < 40110018; --wihtout quotes
the query returns a character to numeric conversion error.

What is the correct way (maybe some function...) to compare char (actually integer) values with another number.

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 07-02-04, 08:24
gurey gurey is offline
Registered User
 
Join Date: Aug 2003
Location: Argentina
Posts: 780
Hi,

If you work with characters, the correct form is columnname[x,y], but if you work with numbers, then does not.
I think that you can create a stored procedure and convert value with a LET.

Gustavo.
Reply With Quote
  #3 (permalink)  
Old 07-02-04, 10:29
fprose fprose is offline
Registered User
 
Join Date: Apr 2003
Location: Phoenix, AZ
Posts: 177
You need to CAST the character field (or a piece of it) as a true number (like integer) and then you can perform your compares.

For example:

select first 20 ssn
from client_ssn
where cast (ssn as integer) between 300000000 and 400000000
;

select first 20 ssn
from client_ssn
where cast (ssn[4,5] as integer) = 67
;
__________________
Fred Prose
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