ITeye博客

获取某时间段的数据

LvMax · 2011-05-30 20:47 · Sql Server · 数据库 · Markdown


declare   @dt   datetime
set   @dt= '2004/08/25 '

--一周內
select   *   from   tb   where   datediff(day,@dt,getdate()) <=7     --@dt相當於日期字段

--一個月內
select   *   from   tb   where   datediff(month,@dt,getdate()) <=1

--半年內
select   *   from   tb   where   datediff(month,@dt,getdate()) <=6 

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。