在access中進(jìn)行時(shí)間的比較sql語(yǔ)句很簡(jiǎn)單,如select * from table where thetime>#"& now() &"#這樣即可
在mssql就不能這樣,要用datediff語(yǔ)句和getdate()函數(shù)進(jìn)行比較。
如select count(*) from table where datediff(s,getdate(),thetime)>0,我自己特別做了個(gè)50萬(wàn)條數(shù)據(jù)的的表,執(zhí)行這條語(yǔ)句差不多需要1200毫秒。
后來(lái)研究了一下,發(fā)現(xiàn)其實(shí)不需要用datediff函數(shù),可以直接使用>來(lái)比較,語(yǔ)句如下:select count(*) from table where thetime>getdate(),這樣差不多只要750毫秒,快了將近500毫秒。
在mssql就不能這樣,要用datediff語(yǔ)句和getdate()函數(shù)進(jìn)行比較。
如select count(*) from table where datediff(s,getdate(),thetime)>0,我自己特別做了個(gè)50萬(wàn)條數(shù)據(jù)的的表,執(zhí)行這條語(yǔ)句差不多需要1200毫秒。
后來(lái)研究了一下,發(fā)現(xiàn)其實(shí)不需要用datediff函數(shù),可以直接使用>來(lái)比較,語(yǔ)句如下:select count(*) from table where thetime>getdate(),這樣差不多只要750毫秒,快了將近500毫秒。

