Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two tables Emp and Dept. Emp consists of Empno(pk),Deptno(FK),Ename,Hiredate and Dept consists Deptno(pk),Dname,Loc.
I want query to get all details of employee who joined recently in each department.
Posted

1 solution

Hi
Here is the solution you can get recently joined employee in organaization.



SQL
SELECT E.*,D.* FROM Emp E INNER JOIN Dept D ON E.Deptno = D.Deptno
WHERE CONVERT(VARCHAR,E.Hiredate,101) > CONVERT(VARCHAR,DATEADD(DAY,-30,GETDATE()),101)
Order by D.Dname, E.Hiredate Desc,  E.Ename



It will display only those employee who was joined in last 30 days. but if you want increase or decrease day replace -30 with your value.


I hope this will help you! :)


Please let me know, if still you don't have solution.

Thanks,
Imdad
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900