I'm trying to filter my data using dates in the WHERE
clause to get a good idea of when stuff happened. However, when I run the query I get no results and the query takes about a minute to fully complete.开发者_开发技巧 Any help is always greatly appreciated.
Declare @date datetime
set @date = getdate() - 11
Select ColumnA,ColumnB
From TableA
Where DateCreated >= @date And DateCreated < GetDate()
You don't have any records in your table that fall into that date range.
or...
DateCreated
isn't a datetime
field.
It takes a minute likely because you don't have an index on that field and SQL is running a table scan to check every record.
精彩评论