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

请教一个存储过程,如何选出生日是在上周的人
如题,SQT可以根据今天的日期,选出birthDay(dateTime类型)是在上个星期的人吗?

------解决方案--------------------
select * from table where
(month(birthDay) between month(dateadd(day,-7,getdate())) and month(getdate()))
and
day(birthDay) between day(dateadd(day,-7,getdate())) and day(getdate()))
------解决方案--------------------
--本来我以为我的正解,但是考虑到如果今天在一年第一周内的情况,所以还要作如下修改:

select * from table where datepart(week,birghDay)+1=datepart(week,getdate()) or
datepart(week,birghDay)-52=datepart(week,getdate())