SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Houston
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with Using Numbers in SELECT Statement

    I'm trying to query the database for a match in a column that contains numbers. When I try one number, like this:
    Code:
    "SELECT * FROM authors WHERE AuthorID = " & intNumber1
    everything is fine. However, when I try this:
    Code:
    "SELECT * FROM authors WHERE AuthorID = " & intNumber1 & " OR " & intNumber2
    all records are returned. The field I am looking through is a number/primary key field. Why is my SELECT returning everything?

    I'm using Access DB on ASP platform.

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well you're making the query be

    WHERE AuthorID=2 OR 3

    since 3 is non-zero, it's always a true WHERE clause. i think you want it to be this

    WHERE AuthorID=2 OR AuthorID=3

    i don't know about Access, but i'm sure you could use IN() instead:

    WHERE AuthorID IN(2, 3)
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Houston
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dr. Larry-

    I just discovered my idiocy a few minutes ago. Sorry for such a silly post.
    Code:
    AuthorID =
    must be used every time.


Bookmarks

Posting Permissions

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