当天或昨天,把函数放在getdate()而不要放在列上当天: where col>=convert(varchar(10),getdate(),120) AND col<convert(varchar(10),dateadd(day,1,getdate()),120)昨天: where col>=convert(varchar(10),dateadd(day,-1,getdate()),120) AND col<convert(varchar(10),getdate(),120)其他的可能查询方式我相信你自己可以同样写出。
可以改为强制查询使用索引:
select id from t with(index(索引名)) where num=@num
--那么用到时如果是
select col from tb with(index=索引) where convert(varchar(10),col,120)='2011-09-02'
--那这个索引还有用么?起的到检索效果么?
有函数 用不了索引的
select col from tb
where col>='2011-09-02'
AND col<'2011-09-03'
昨天的就是 -1天与-2天的关系。后面用函数应该不影响吧。
where col>=convert(varchar(10),getdate(),120)
AND col<convert(varchar(10),dateadd(day,1,getdate()),120)昨天:
where col>=convert(varchar(10),dateadd(day,-1,getdate()),120)
AND col<convert(varchar(10),getdate(),120)其他的可能查询方式我相信你自己可以同样写出。