By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,265 Members | 1,333 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,265 IT Pros & Developers. It's quick & easy.

SQL query related to Date.

P: 92
1.query to find out all employee IDs whose birthday fall today ?

2.query to find out 10th specific record?

Thank u,
Limno.
Feb 11 '09 #1
Share this Question
Share on Google+
2 Replies


100+
P: 152
gpl
@Limno
Not only does this sound like homework, you havent transcribed the question completely. What does 10th specific record mean ?

A clue to the birthday issue - the DatePart function can retrieve the day part of a date and also the month part of the date, so your Where clause would need to do something like

Where month part of birthday = month part of today
and day part of birthday = day part of today

The year is of course irrelevant, as birthdays occur every year, except for the special case of leap days.

The Books Online help for SQL server is very good
Feb 12 '09 #2

ammoos
100+
P: 100
1.
SELECT Emp_ID, BirthDate
FROM Table1
Where
datepart(day,BirthDate)=datepart(day,GETDATE())
AND
datepart(month,BirthDate)=datepart(month,GETDATE() )
ORDER BY Emp_ID

2.
select top 1 Emp_ID, BirthDate from
(
SELECT top 10 Emp_ID, BirthDate
FROM Table1
Where
datepart(day,BirthDate )=datepart(day,GETDATE())
AND
datepart(month,BirthDate )=datepart(month,GETDATE())
ORDER BY Emp_ID
) tempTable
ORDER BY Emp_ID desc
Feb 12 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.