SQL时间区间条件查询三种方法比较

在某一时间区间条件的查询 

后来再了一次测试,数据比较少,大概500条数据,结果如下: 

declare   @ct   datetime 
  
set @ct=getdate() 
SELECT  * FROM [siso].[dbo].[Activity] WHERE ASDateTime < getDate() and AEDateTime > getDate();
select   datediff(ms,   @ct   ,getdate())   as   '查询时间(毫秒)' 
(16 ms)   


set @ct=getdate()  
SELECT  * FROM [siso].[dbo].[Activity] WHERE getDate() BETWEEN ASDateTime AND AEDateTime;
select   datediff(ms,   @ct   ,getdate())   as   '查询时间(毫秒)'  
(36 ms)  

 
set @ct=getdate()  
SELECT * FROM [siso].[dbo].[Activity] where datediff(S,ASDateTime,@ct)>0 AND  datediff(S,AEDateTime,@ct)<0; 
select   datediff(ms,   @ct   ,getdate())   as   '查询时间(毫秒)'  
(50 ms) 


你可能感兴趣的:(sql,sqlserver,时间区间比较)