SQL Server Query Last 6 Months

Viewed 7978

Every time I update the data I want it to only reflect the last 6 months of data. Below is my current query. Can someone assist me with this?

SELECT ar.[Report Date]
,ar.Facility
,SUM (ar.[0-30]) AS [0-30]
,SUM (ar.[31-60]) AS [31-60]
,SUM (ar.[61-90]) AS [61-90]
,SUM (ar.[91-120]) AS [91-120] 
,SUM (ar.[120+]) AS [120+]
FROM DBO.ARByPayer AS ar
WHERE ar.[Current Financial Class] <> 'Lien'
GROUP BY ar.Facility, ar.[Report Date]
ORDER BY ar. [Report Date]
2 Answers

You need to add this to your where clause, if I understand what you are after correctly:

and ar.[Report Date] > DATEADD(m, -6, GetDate())

You can add this clause to your WHERE section:

DATEADD(d, 180, ar.[Report Date]) > getdate()
Related