Below is my SQL statement
DECLARE @dStart datetime ,
@dEnd datetime
SET @dEnd = GETDATE()
SET @dStart = DATEADD(mm, -6, @dEnd)
Select * from MyTable
Where TheDate Between @dStart AND @dEnd
This will return all the records from today minus 6 months data.
But I want this months data plus only the previous 5 months data.
Currently it will return records from March as well.
Instead of
You might use
This will truncate date to first of current month and substract five months from it.