Correct Way to Get Date Between Dates In SQL Server
Posted
by Chuck Haines
on Stack Overflow
See other posts from Stack Overflow
or by Chuck Haines
Published on 2010-06-18T15:58:01Z
Indexed on
2010/06/18
16:03 UTC
Read the original article
Hit count: 323
sql
|sql-server
I have a table in SQL server which has a DATETIME field called Date_Printed. I am trying to get all records in the table which lie between a specified date range. Currently I am using the following SQL
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = '2010-01-01'
SET @EndDate = '2010-06-18 12:59:59 PM'
SELECT * FROM table WHERE Date_Printed BETWEEN @StartDate AND @EndDate
I have an index on the Date_Printed column. I was wondering if this is the best way to get the rows in the table which lie between those date or if there is a faster way. The table has about 750,000 records in it right now and it will continue to grow. The query is pretty fast but I'd like to make it faster if possible.
© Stack Overflow or respective owner