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

求一条SQL语句!!(保证迅速结贴)
本人所要求的SQL语句其实很简单,但就是通不过:
查询从当前天数起至前7天期间的所有记录(简单讲即本星期的最新记录),本人这样实现,但提示语句未结束:请高手帮忙!(sql   server2000数据库)

select   *   from   dt   where   d_date> datediff( "d ",7,getdate())   and   d_date <=getdate()   order   by   d_date   desc

请高手详解,保证迅速结贴!


------解决方案--------------------
如果d_date是DateTime类型的话, 只需要这样写(不需要DateDiff函数的):

select * from dt where d_date > getdate() - 7 and d_date <= getdate() order by d_date desc


------解决方案--------------------
至前7天期间,理解为7天后了,改下
select * from dt where convert(char(10),d_date,120)> =convert(char(10),dateadd(day,-7,getdate()),120)
and d_date <=convert(char(10),getdate(),120) order by d_date desc


------解决方案--------------------
select * from dt where DATEDIFF(day,GETDATE(),d_date) between 0 and 7