I have a dataset of subscriptions in a table that looks something like this:
Table:
UserID
Subscription_type
Subscription_end_date
I’m trying to build a report in SSRS that shows a list of all subscriptions that are going to expire somewhere in the next month. The report gets sent on the first of every month and needs to show all the rows that are going to expire in the next month.
For example: a report sent on 01-07-2021 needs to show all subscriptions that are going to expire during August (so all subscription_end_date with a value from 01-08-2021 to 31-08-2021).
At first I thought using a where statement like the below one would be the answer:
WHERE [Subscription_end_date] = DATEADD(MONTH, 1, GETDATE())
But somehow it doesn’t return any values. I would like to know if my solution is in the right direction and that DATEADD combined with the GETDATE should do the trick or that I have to search it in a whole other statement.
Advertisement
Answer
You need to just check your target date is within the desired range, try
where Subscription_end_date >= dateadd(month,1,convert(date,getdate())) and Subscription_end_date < dateadd(month,2,convert(date,getdate()))
Assuming of course you are running your report on the 1st of each month.