SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Birthday SQL
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

3 Posts

Posted - 10/31/2013 :  17:38:35  Show Profile  Reply with Quote
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.

Aged Yak Warrior

982 Posts

Posted - 10/31/2013 :  21:16:02  Show Profile  Reply with Quote

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 @employee
where dob >= dateadd(d, datediff(d, 0, getdate()), 0)
order by dob
Go to Top of Page

In (Som, Ni, Yak)

17684 Posts

Posted - 10/31/2013 :  23:07:15  Show Profile  Reply with Quote

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)
from 	@employee
order by next_bd

Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000