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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WHERE clause between 2 dates

Status
Not open for further replies.

TomBarrand

Programmer
Aug 9, 2000
162
GB
Hi,

I have the following SQL and would like to add an extra WHERE clause that would display records that were between two dates, any ideas about how I would do this?

SELECT TSDate, EmployeeName, Period, WorkType
FROM timesheet_Lines_tbl
WHERE Period <> 'NCR'
ORDER BY WorkType, EmployeeName

Cheers,

Tom
 
SELECT TSDate, EmployeeName, Period, WorkType
FROM timesheet_Lines_tbl
WHERE Period <> 'NCR'
AND TSDate >= '1 Dec 2000' AND TSDate <= '1 Jan 2000'
ORDER BY WorkType, EmployeeName


Hope this helps,

Chris Dukes
 
You can also use:

TSDate BETWEEN '1 Dec 2000' AND '1 Jan 2000'

which is equal to

TSDate >= '1 Dec 2000' AND TSDate <= '1 Jan 2000'

Does anyone know if any or both would use an index on the field if there was one?

JB


 
YES,

both should use an index if an index exists on TSDate.

You can test this by looking at the execution plan in Query Analyzer.

Chris Dukes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top