Michael, your code fails when one year rolls over to another
for example, with the test cases and the presumed current date modified:
declare @emp table
(empid int identity(1,1) primary key clustered, dob datetime not null)
insert into @emp (dob)
SELECT convert(datetime,'1962-01-01 00:00:00.000') AS dob UNION ALL
SELECT convert(datetime,'1958-12-31 00:00:00.000') AS dob UNION ALL
SELECT convert(datetime,'1960-02-29 00:00:00.000') AS dob UNION ALL
SELECT convert(datetime,'1990-08-30 00:00:00.000') AS dob UNION ALL
SELECT convert(datetime,'1990-09-03 00:00:00.000') AS dob UNION ALL
SELECT convert(datetime,'1990-09-04 00:00:00.000') AS dob UNION ALL
SELECT convert(datetime,'1985-09-05 00:00:00.000') AS dob UNION ALL
SELECT convert(datetime,'1985-09-10 00:00:00.000') AS dob UNION ALL
SELECT convert(datetime,'1985-09-11 00:00:00.000')
select
a.*,
BirthdayThisYear = dateadd(yy,datediff(yy,dob,getdate()),dob),datediff(dd,'Dec 31, 2010' ,dateadd(yy,datediff(yy,dob,getdate()),dob))
from
@emp a
where
--Birthday between tomorrow and 7 days from today
datediff(dd,'Dec 30, 2010' ,dateadd(yy,datediff(yy,dob,getdate()),dob))
between 1 and 7
The expected result is emp 1 and 2 returned, but you only get emp 2. Lowell's has the same problem.