Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Filter records by date -3 months

$
0
0

Hello guys,

I am aware that this should be very simple and it might be already answered but i keep tried and can't make it work.
I have a simple query that looks like this :

What i need to do is display only the records that correspond to the last 3 months (but not the current one) , don't taking in count the days , only the months.
Example : If i execute it today 20-10-2020 it should show me results from July , August and September , also it must work the year , like if i execute it on February 2021 , it should display November 2020 , December 2020 and January 2021.
I tried to do it by declaring variables but i have problems with converting data type.
I tried this :
declare @p datetime
set @p = DATEADD(month, -3, GETDATE())
select @p
declare @a datetime
set @a = FORMAT(@p, 'yyyy-MM')
select @a
"Conversion failed when converting date and/or...

Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>