小于不就可以了 select * from employee where convert(char(7),[date],120)>convert(char(7),getdate(),120) select * from employee where convert(char(7),[date],120)<convert(char(7),getdate(),120)
上面的也可以 select * from employee where rq>=convert(char(10),dateadd(dy,-day(getdate())+1,getdate()),111) and rq<dateadd(m,1,convert(char(10),dateadd(dy,-day(getdate())+1,getdate()),111)) 但如果日期使用函数,索引无效,速度很满
convert(char(10),时间,120)这样可以直接比 1999-01-01(10位)
select * from table1 where datepart(yy,date1)>datepart(yy,getdate()) or datepart(mm,date1)>datepart(mm,getdate())
小于不就可以了
select * from employee where convert(char(7),[date],120)>convert(char(7),getdate(),120)
select * from employee where convert(char(7),[date],120)<convert(char(7),getdate(),120)
select * from employee
where rq>=convert(char(10),dateadd(dy,-day(getdate())+1,getdate()),111)
and rq<dateadd(m,1,convert(char(10),dateadd(dy,-day(getdate())+1,getdate()),111))
但如果日期使用函数,索引无效,速度很满
1999-01-01(10位)
datepart(mm,date1)>datepart(mm,getdate())