Can any one tell me how to get the list of an employee who have their birthdays today ....
Thanks, Vishal
Can any one tell me how to get the list of an employee who have their birthdays today ....
Thanks, Vishal
SELECT *
FROM Employees
WHERE DATEPART(d, DateOfBirth) = DATEPART(d, GETDATE())
AND DATEPART(m, DateOfBirth) = DATEPART(m, GETDATE())
Ideally a bit more information on the structure of your data sources would help, but a simple answer providing your employee records have a D.O.B. field would be to compare the day and month of this against the current system date in the where clause of your query.
Something along the following lines:
select * from wherever
where
....
(
datepart(d, EmployeeDOB) = datepart(d, getdate()) and
datepart(m, EmployeeDOB) = datepart(m, getdate())
)
.....
WHERE
month and day of employee's birthday match today's month and day (obviously). More specific instructions would require more input.
You can do something like this:
select e.name from employeeTable e
where right(e.birthday) = right(convert(varchar(8), getdate(), 112), 4)
or
select e.name from employeeTable e
where datepart(d, e.birthday) = datepart(d, getdate())
and datepart(m, e.birthday) = datepart(m, getdate())
Although this is much more long winded, it does avoid having to scan the entire table looking for matches.
WITH
a_century AS
(
SELECT 1 AS year
UNION ALL
SELECT year * 2 + 0 AS year FROM a_century WHERE year < 64
UNION ALL
SELECT year * 2 + 1 AS year FROM a_century WHERE year < 64
)
SELECT
*
FROM
yourTable
INNER JOIN
a_century
ON yourTable.birthday = DATEADD(year, -a_century.year, DATEADD(day, DATEDIFF(day, 0, getDate()), 0))