Wednesday, February 15, 2012

Even and Odd numbers

I need to figure out how to pull records if the id is even or odd.
ie
ID Name
1 bill
2 john
3 joe
4 jane
for example i need a idea of a select statement that will pull the even records 2 and 4.
is this possible?you should able to use the modulo operator... something like (for even)

select *, CAST(ID AS int) % CAST(2 AS int) AS Modulo
from table where Modulo = 0

I think that should do it...

To do it for the odd numbers try this...

select *, CAST(ID AS int) % CAST(2 AS int) AS Modulo
from table where Modulo = 1|||thanks rockslide i will give that a crack.

No comments:

Post a Comment