Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Rows in Date Range 1

Status
Not open for further replies.

Ajb2528

Technical User
Feb 22, 2002
270
GB
Hi,

I am using SQL 7.0 and have a problem selecting rows within a date range.

The table has a StartDate and EndDate column (datetime data type) and contains the start date and end date of the event. What I require is to return any rows that span the start date and end date when the StartDate and EndDate range is within a date input.

For example the table could contain:
StartDate EndDate
--------- -------
01/02/2005 04/02/2005 (dd/mm/yyyy format)

If I input a StartDate of 01/02/2005 (dd/mm/yyyy) I would like the above row returned.

Can anyone help me on this??

Regards,

Alan
 
Are you just inputting a single date and want to return all rows where that date falls between the startdate and enddate?

Code:
DECLARE @date datetime
SET @date = '20040201'

SELECT * FROM t
WHERE @date BETWEEN startdate AND enddate

--James
 
James,

Thanks very much!! That was just what I was after!

Regards,

Alan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top