Link to home
Start Free TrialLog in
Avatar of shaynegw
shaynegwFlag for Canada

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
Avatar of oratim
oratim

select decode(mod(STREET_NUMBER_FROM,2),1,'ODD',0,'EVEN','ERROR') from street_numbers

Avatar of shaynegw

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
sorry,

if they are text use this

select decode(mod(to_number(STREET_NUMBER_FROM),2),1,'ODD',0,'EVEN','ERROR') from street_numbers

but that will only work if the data is numeric, so 123A will cause error ORA-01722: invalid number

ASKER CERTIFIED SOLUTION
Avatar of oratim
oratim

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial