Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

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

kattlees
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.

waterduck
Aged Yak Warrior

Malaysia
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

khtan
In (Som, Ni, Yak)

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



KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next 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.3 seconds. Powered By: Snitz Forums 2000