Link to home
Start Free TrialLog in
Avatar of spoowiz
spoowizFlag for United States of America

asked on

even/odd function

is there a ISEVEN or ISODD function in SQL? specifically mysql?
thanks
Avatar of Roonaan
Roonaan
Flag of Netherlands image

You can use modules 2 or bitwise AND 1.

-r-
Avatar of spoowiz

ASKER

sounds promising.
how would that look in a sql stmt such as:

select * from table1 where ISEVEN(field1)

thanks
ASKER CERTIFIED SOLUTION
Avatar of todd_farmer
todd_farmer
Flag of United States of America image

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
Note also that if you are using MySQL 5.0, you can declare your own ISEVEN function:

mysql> create function ISEVEN (i INT) RETURNS INT RETURN NOT(i&1);
Query OK, 0 rows affected (0.13 sec)

mysql> select ISEVEN(3);
+-----------+
| ISEVEN(3) |
+-----------+
|         0 |
+-----------+
1 row in set (0.06 sec)

mysql> select ISEVEN(4);
+-----------+
| ISEVEN(4) |
+-----------+
|         1 |
+-----------+
1 row in set (0.00 sec)

Avatar of spoowiz

ASKER

excellent. thanks