Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2004
    Posts
    19

    Unanswered: 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?

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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
    Last edited by rokslide; 03-30-04 at 23:25.

  3. #3
    Join Date
    Jan 2004
    Posts
    19
    thanks rockslide i will give that a crack.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •