SQLTeam.com | Weblogs | Forums

I had one joining date query question


#1

I have to find employee records who have completed 100 days since their joining


#2

What have you tried?


#3

SELECT *
FROM dbo.emps
WHERE join_date < DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()) - 100, 0)


#4

Yes, this also worked. I had tried this way and it was also SELECT EmpName, EMPID FROM Employee
WHERE DATEDIFF(dd,JOININGDATE, GETDATE()) >100;

Thank you for your correct and useful query btw.


#5

This method won't use an index on JOININGDATE because the use of that column within a function is not SARGable, and thus will be inefficient, so preferable to do it Scott's way.