Results 1 to 3 of 3

Thread: query for even and odd numbers

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2006
    Posts
    719

    query for even and odd numbers

    Code:
    "Select * from Table WHERE ItemNum=2 OR ItemNum=4 OR ItemNum=6"
    i use the code above to select ItemNum w/ even number.. but the problem is how about 8 and above?

    the same w/ the odd number

    what should I do?

  2. #2
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: query for even and odd numbers

    Which database are you using? Oracle and SQL Server have MATH functions in SQL.

    http://www.java2s.com/Code/Oracle/Nu...ctions/MOD.htm


    Mod operator is written as % (percentage) in T-SQL.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: query for even and odd numbers

    vb Code:
    1. "Select * from Table WHERE ItemNum > 0 AND ItemNum MOD 2 = 0"

Posting Permissions

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



Click Here to Expand Forum to Full Width