Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
kattlees
Starting Member
3 Posts |
Posted - 2013-10-31 : 17:38:35
|
We have a DOB field that shows the full DOB of our employee. We send them a small gift each year so I need to see a list of employees by their month and date but not the year. After their birthday passes it will go to the bottom. So right now, 10-31 it would show birthdays starting in November then show December, Jan, Feb, etc. |
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2013-10-31 : 21:16:02
|
[code]declare @employee table(name varchar(30), dob datetime)insert into @employee select'waterduck', '20131031' union all select'waterchicken', '20131101' union all select'waterdog', '20131201' union all select'watercat', '20140101' union all select'waterrat', '20140201'select day(dob), month(dob), name from @employeewhere dob >= dateadd(d, datediff(d, 0, getdate()), 0)order by dob[/code] |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2013-10-31 : 23:07:15
|
[code]select *, next_bd = case when dateadd(year, year(getdate()) - year(dob), dob) < getdate() then dateadd(year, year(getdate()) - year(dob) + 1, dob) else dateadd(year, year(getdate()) - year(dob), dob) endfrom @employeeorder by next_bd[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
|
|
|
|
|