where DateDiff(Day,DateAdd(year,DateDiff(year,Birthday,GetDate()),Birthday),GetDate()) between -1 and 0
order by datepart(m,Birthday),datepart(d,Birthday)
--between -1 and 0 包含今天、明天
--between -2 and 0 包含今天、明天、后天
--between 0 and 1 包含今天、昨天
--between 0 and 2 包含今天、昨天、前天
order by datepart(m,Birthday),datepart(d,Birthday)
--between -1 and 0 包含今天、明天
--between -2 and 0 包含今天、明天、后天
--between 0 and 1 包含今天、昨天
--between 0 and 2 包含今天、昨天、前天
解决问题:假如三天之内,是8月30-9月1日之间,如果用datepart(m,staff_time)=datepart(m,getdate()) 查不到的问题
生日提醒SQL(修正跨年):
where DateDiff(Day,DateAdd(year,DateDiff(year,Birthday,GetDate()),Birthday),GetDate()) between -365 and 0 or
DateDiff(Day,DateAdd(year,DateDiff(year,Birthday,GetDate())+1,Birthday),GetDate()) between -365 and 0
order by datepart(m,Birthday),datepart(d,Birthday)
DateDiff(Day,DateAdd(year,DateDiff(year,Birthday,GetDate())+1,Birthday),GetDate()) between -365 and 0
order by datepart(m,Birthday),datepart(d,Birthday)