If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Select query between two figures

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-24-04, 11:50
spacdude spacdude is offline
Registered User
 
Join Date: Sep 2004
Location: UK
Posts: 15
Question 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.
Reply With Quote
  #2 (permalink)  
Old 09-24-04, 16:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-25-04, 07:48
spacdude spacdude is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 09-25-04, 08:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 09-27-04, 05:27
spacdude spacdude is offline
Registered User
 
Join Date: Sep 2004
Location: UK
Posts: 15
Thanks it works now
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On