This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input data and expected output for finding the upcoming birthdays of students.
Input Data:
1 2 3 4 5 6 7 8 |
EmpID EmpName DOB ----------- ---------- ---------- 1 Anvesh 1988-01-26 2 Jenny 1991-04-09 3 Alpesh 1993-06-10 4 Roy 1991-02-14 5 Manish 1985-03-05 6 Nupur 1988-08-08 |
Expected Output for May 2018:
1 2 3 |
EmpID EmpName DOB ----------- ---------- ---------- 5 Manish 1985-05-05 |
Create a table:
1 2 3 4 5 |
CREATE TABLE tbl_Employee (EmpID INT, EmpName VARCHAR(10), DOB DATE) INSERT INTO tbl_Employee VALUES (1,'Anvesh','19880126'),(2,'Jenny','19910409'),(3,'Alpesh','19930610') ,(4,'Roy','19910214'),(5,'Manish','19850505'),(6,'Nupur','19880808') |
Solution:
1 2 3 |
SELECT * FROM tbl_Employee WHERE DATEADD( Year, DATEPART( Year, GETDATE()) - DATEPART( Year, DOB), DOB) BETWEEN CONVERT( DATE, GETDATE()) AND CONVERT( DATE, GETDATE() + 30) |
Please try the different solution for this puzzle and share it via comment...