Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date Range

Author  Topic 

datachick
Starting Member

3 Posts

Posted - 2015-02-12 : 17:29:04
Hi I am running a query with a date from the beginning of the year and when I hardcode the dates it takes less than 1 minute for query; however, when i add the this formatting and calculate values based on GETDATE() it takes more than 10 minutes to return 11000 rows. is there another way to do this so that i don't have to modify annually?

this is taking too long...

HID_Date >= DATEADD(yy,DATEDIFF(yy,0,GETDATE()),0) and
HID_Date <= DATEADD(ms,-3,DATEADD(yy,0,DATEADD(yy,DATEDIFF(yy,0,GETDATE())+1,0)))

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-02-12 : 17:42:25
Try putting the DATEADDs into two variables and then use the variables in the query.

Is HID_Date indexed?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -