I used to only have these kind of records in my "period"-column: CW 01, CW 02,...,CW 21
To retrieve only a certain range of calendar weeks I used this statement:
Select Period,....,
where
(CONVERT(tinyint, SUBSTRING(Period, 4, 2)) >= DATEPART(week, GETDATE()) - 5), ...
Now I have to add records like MO 05, MO 06 for monthly values. Obviously I need the CW and MO values now.
So, instead of Datepart(week,...), I thought I could use "month" but I couldn't find a way to modify the substring stmt, in order to retrieve the last 6 weeks or 2 months from now.
Do you have an idea how to solve this? All I want is: "Show me the records for the last 2 months but also the CW entries within this 2 months from now range. I'm using MSSQL 2012.
UPDATE: fiddle
Thank you.