if object_id(‘tempdb..#tt‘)>0 drop table #tt
--模拟数据
create table #tt (cc datetime)
insert into #tt values(‘2013-02-01‘)
insert into #tt values(‘2013-05-16‘)
insert into #tt values(‘2013-05-21‘)
insert into #tt values(‘2013-06-01‘)
insert into #tt values(‘2013-07-15‘)
insert into #tt values(‘2013-08-17‘)
insert into #tt values(‘2014-02-05‘)
insert into #tt values(‘2014-04-16‘)
insert into #tt values(‘2014-05-21‘)
insert into #tt values(‘2014-06-18‘)
insert into #tt values(‘2014-07-21‘)
insert into #tt values(‘2014-08-14‘)
insert into #tt values(‘2014-08-27‘)
select * from #tt
--提取数据
select *
from #tt
WHERE CASE WHEN DATEADD(YEAR,DATEDIFF(YEAR,cc,GETDATE()),cc)<GETDATE()
THEN DATEADD(YEAR,DATEDIFF(YEAR,cc,GETDATE())+1,cc)
ELSE DATEADD(YEAR,DATEDIFF(YEAR,cc,GETDATE()),cc)
END BETWEEN GETDATE() AND DATEADD(m,2,GETDATE())
提取从当天起,后两个月生日人员名单,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/sp-oh-dear/p/3791576.html