日期:2014-05-18  浏览次数:20537 次

读取最近20天或40天或2个月的记录
读取最近20天或40天或2个月的记录
请高手指点

------解决方案--------------------
SELECT * FROM TableName WHERE DATEDIFF(DAY,记录日期,GETDATE()) <=20
SELECT * FROM TableName WHERE DATEDIFF(DAY,记录日期,GETDATE()) <=40
SELECT * FROM TableName WHERE DATEDIFF(DAY,记录日期,GETDATE()) <=60
------解决方案--------------------

SELECT * FROM TableName WHERE 记录日期 between getdate()-20 and getdate()
SELECT * FROM TableName WHERE 记录日期 between getdate()-40 and getdate()
SELECT * FROM TableName WHERE 记录日期 between getdate()-60 and getdate()
------解决方案--------------------
DATEDIFF(DAY,记录日期,GETDATE())
就用DATEDIFF函数可以轻松搞定