Correct Way to Get Date Between Dates In SQL Server -


I have a table in the SQL server that has a date field that has been datored. I am trying to get all the records in the table which is 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 SELECT WHERE dated @tartdate and @EndDate

I have an index on the Date_Printed column. I was thinking that this is the best way to get the rows in the table, which is between those dates or if there is a fast way in this table right now about it 750,000 Cord and will continue to grow it. The question is very fast, but if possible, I want to do it fast.

I would recommend that you use:

  DECLARE @StartDate DATETIME DECLARE @EndDate DATETIME SET @StartDate = '2010-01-01' SET @EndDate = '2010-06-19' Select [someColumn]. .. from the table WHERE Date_Printed & gt; = @StartDate and Date_Printed & lt; @EndDate  

Do not know if the last second of that day can come!


Comments