I have a query when I run like this
select emp_name, dt_of_join
from emp_mst
where dt_of_join = '2015-09-14'
I get one record from the table.
But when I try to run in dynamically like below
SELECT emp_name, Dt_Of_Join
FROM emp_mst
WHERE Dt_Of_Join = DATEADD(month, -6, GETDATE())
it doesn't return any records. WHY ???
I am using SQL Server 2008.
datetimeinstead of adate. Is Dt_Of_Join a datetime field filled with only dates? You could try the following:DATEADD(month, -6, cast(GETDATE() as date))select getdate()just to verify that the date is correct on your server.Dt_Of_Joinisdatetimedataype and ur solution also didn't worked giving error asType date is not a defined system type.2016-03-14 18:19:29.993i guess it is working2015-09-14has a time between 00:00:00 and 18:19:29 @Me.Name is probably right. You have to keep in mind, that DATETIME values carry a time and today at 18:19 minus 6 months is then at 18:19...