I have created the below query to capture the 1st day of the month for the data that i have archived.
sELECT Distinct CAST(CAST(YEAR(Archived) AS VARCHAR(4)) + RIGHT('0' + CAST(DATEPART(MM, Archived) AS VARCHAR(12)),2) AS INT) as 'ArchivedYrMo' FROM [RCSC].[dbo].[IAQ_Archive] I
ORDER BY I.Archived DESC
However I also need to create a query pull the previous month. I would need the results to pull 201310 if i were running the query today and if i was to run the query in Jan the results would need to be 201312.