We help IT Professionals succeed at work.

even/odd function

spoowiz
spoowiz asked
on
535 Views
Last Modified: 2008-02-26
is there a ISEVEN or ISODD function in SQL? specifically mysql?
thanks
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2006

Commented:
You can use modules 2 or bitwise AND 1.

-r-

Author

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

select * from table1 where ISEVEN(field1)

thanks
Top Expert 2006
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Top Expert 2006

Commented:
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)

Author

Commented:
excellent. thanks
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.