开发者

SQL query returns nothing after minute

开发者 https://www.devze.com 2023-04-01 05:12 出处:网络
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 comp

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消