shaynegw
asked on
Best way to determine even/odd using SQL
Hi
I have two text fields in a table called STREET_NUMBER_FROM and STREET_NUMBER_TO that only have numerical characters, what is the fastest SQL method for determining if one or both of the fields represents an even or odd number?
Thanks and take care,
Shayne
I have two text fields in a table called STREET_NUMBER_FROM and STREET_NUMBER_TO that only have numerical characters, what is the fastest SQL method for determining if one or both of the fields represents an even or odd number?
Thanks and take care,
Shayne
select decode(mod(STREET_NUMBER_F ROM,2),1,' ODD',0,'EV EN','ERROR ') from street_numbers
ASKER
Hi
I made a mistake, there are characters in these fields, so I have to deal with values like 1A, 2B, 123C, etc. So I'll also need a method to filter out the characters before determining odd/even.
Take care,
Shayne
I made a mistake, there are characters in these fields, so I have to deal with values like 1A, 2B, 123C, etc. So I'll also need a method to filter out the characters before determining odd/even.
Take care,
Shayne
sorry,
if they are text use this
select decode(mod(to_number(STREE T_NUMBER_F ROM),2),1, 'ODD',0,'E VEN','ERRO R') from street_numbers
but that will only work if the data is numeric, so 123A will cause error ORA-01722: invalid number
if they are text use this
select decode(mod(to_number(STREE
but that will only work if the data is numeric, so 123A will cause error ORA-01722: invalid number
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.