By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,379 Members | 1,435 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,379 IT Pros & Developers. It's quick & easy.

Between & Dates

P: 5
I am trying to query SQL, based on a date

For each term I have a record in the "TermDate" table:

TemName StartDate EndDate
Term 1 9/1/2007 11/21/2007
Term 2 11/22/2007 1/29/2008
Term 3 ... ...

Seems easy enough, but I can't get it to pull the appropriate record. if xDate = 9/20/2007, the query should return me Term 1, for example.

Both date fields are smalldate types

I tried using a "Between" statement, but that didnt go to well - any ideas?
Mar 24 '08 #1
Share this Question
Share on Google+
3 Replies


ck9663
Expert 2.5K+
P: 2,878
I am trying to query SQL, based on a date

For each term I have a record in the "TermDate" table:

TemName StartDate EndDate
Term 1 9/1/2007 11/21/2007
Term 2 11/22/2007 1/29/2008
Term 3 ... ...

Seems easy enough, but I can't get it to pull the appropriate record. if xDate = 9/20/2007, the query should return me Term 1, for example.

Both date fields are smalldate types

I tried using a "Between" statement, but that didnt go to well - any ideas?
Can you post your query? Is there an error? a

Expand|Select|Wrap|Line Numbers
  1. WHERE @xDate between StartDate and EndDate 
should be fine. I'm assuming xDate is a variable.

-- CK
Mar 24 '08 #2

debasisdas
Expert 5K+
P: 8,127
Are you getting any error from the query or simply not getting the desired output ?
Mar 25 '08 #3

amitpatel66
Expert 100+
P: 2,367
Try converting xDate to date variable of format MM/DD/YYYY when used with BETWEEN clause
Mar 25 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.