Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2004
    Location
    UK
    Posts
    15

    Question Unanswered: Select query between two figures

    I have a select query for a record that i want to find that is going to be a number between two other dates that I might not know exactly. Basically I don't know how to write it correctly! Number and datetime are columns in the table.

    Here is what I have so far which doesn't work:

    select * from table where Number ='27006' and [datetime] between '%2003-08-16%' and '%2003-08-18%'

    Any help would be appreciated.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    i don't understand the question

    you want a number that is going to be between two other dates?

    numbers and dates aren't comparable

    and you don't know which dates exactly?

    you will have to explain this a bit more clearly

    perhaps also give some examples of the data

    and it wouldn't hurt to let us know which database you're using, because they all have different date functions
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Sep 2004
    Location
    UK
    Posts
    15
    Sorry about that, end of a long day so I probably wasn't thinking very straight. I will try to explain it better now. I think using number as a column was probably confusing. Lets say I have two columns that in a table and I want to perform a SELECT query on them. One column is called "ID" and the other is called "datetime". There may be multiple instances of the same ID but different datetimes for each e.g. ID equaling 27006 and datetime equaling 2003-05-10 and another record with ID being the same and datetime being something else. What I want to do is make a SELECT query that will search for an ID between two datetimes.


    select * from table where ID ='27006' and [datetime] between '%2003-08-16%' and '%2003-08-18%'

    I am using a MS SQL database and this will probably be written in ASP.
    I hope that makes a bit more sense.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    that query looks fine, give it a try

    well, except for the fact that if ID is numeric, you don't want quotes around 27006
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Sep 2004
    Location
    UK
    Posts
    15
    Thanks it works now

Posting Permissions

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