如何查询上周的所有记录?
我用
SET @sql=@sql+' and datediff(Week , begintime , getdate()) >= 0 and datediff(Week ,endtime , getdate())<= 0'
可以查询到本周的记录.
如果要查询昨天,上周,上月,去年的记录应该如何做?
谢谢好心人.
------解决方案--------------------上周SET @sql=@sql+ ' and datediff(Week , begintime , getdate()) =1
上月SET @sql=@sql+ ' and datediff(month, begintime , getdate()) =1
去年SET @sql=@sql+ ' and datediff(year, begintime , getdate()) =1
------解决方案--------------------如果要查询昨天,上周,上月,去年的记录应该如何做?
上周
select * from tb where datediff(week,日期,getdate()) = 1
上月
select * from tb where datediff(month,日期,getdate()) = 1
去年
select * from tb where datediff(year,日期,getdate()) = 1
------解决方案--------------------ls都是正解!