Whose birthday next?

,

sort employee birthday by on coming order. If the person's birthday is yesterday, s/he should be in the bottom.

SELECT     employee_name, birth_date, DATENAME(month, birth_date) AS month, DATENAME(day, birth_date) AS day, DATEDIFF(day, GETDATE(), DATEADD(year, DATEDIFF(year, birth_date, GETDATE()), birth_date)) + ABS(SIGN(DATEDIFF(day, GETDATE(), DATEADD(year, DATEDIFF(year, birth_date, 
                      GETDATE()), birth_date))) - 1) / 2 * 365 AS sort
FROM         employees
WHERE     (birth_date IS NOT NULL) AND (IsEmployed = 1)
ORDER BY DATEDIFF(day, GETDATE(), DATEADD(year, DATEDIFF(year, birth_date, GETDATE()), birth_date)) + ABS(SIGN(DATEDIFF(day, GETDATE(), DATEADD(year, DATEDIFF(year, birth_date, GETDATE()), birth_date))) - 1) / 2 * 365

Rate

4 (1)

Share

Share

Rate

4 (1)