For this problem, you can use several approach to get the result.
Some of them is to unified the result based on the QTR type.
So, maybe its the simple way to get the result.
First, try to get just actual_month QTR based on the YearMonth given.
The query will looks like:
SELECT
QTRType = cast(year(YearMonth as varchar(10)) + '-Actual',
Q1 = case when month(YearMonth) = 3 then Actual_Month else 0 end,
Q2 = case when month(YearMonth) = 6 then Actual_Month else 0 end,
Q3 = case when month(YearMonth) = 9 then Actual_Month else 0 end,
Q4 = case when month(YearMonth) = 12 then Actual_Month else 0 end
FROM Table1
WHERE
year(YearMonth) <= 2010
The query above would return all Actual type QTR.
So, the next step, with same approach, try to get Target type QTR and Projection QTR.
After you get it, just union all the query using union all keyword.
The final query:
SELECT
QTRType = cast(year(YearMonth as varchar(10)) + '-Actual',
Q1 = case when month(YearMonth) = 3 then Actual_Month else 0 end,
Q2 = case when month(YearMonth) = 6 then Actual_Month else 0 end,
Q3 = case when month(YearMonth) = 9 then Actual_Month else 0 end,
Q4 = case when month(YearMonth) = 12 then Actual_Month else 0 end
FROM Table1
WHERE
year(YearMonth) <= 2010
UNION ALL
SELECT
QTRType = cast(year(YearMonth as varchar(10)) + '-Target',
Q1 = case when month(YearMonth) = 3 then Target_Month else 0 end,
Q2 = case when month(YearMonth) = 6 then Target_Month else 0 end,
Q3 = case when month(YearMonth) = 9 then Target_Month else 0 end,
Q4 = case when month(YearMonth) = 12 then Target_Month else 0 end
FROM Table1
WHERE
year(YearMonth) <= 2010
UNION ALL
SELECT
QTRType = cast(year(YearMonth as varchar(10)) + '-Projection',
Q1 = case when month(YearMonth) = 3 then Projection_Month else 0 end,
Q2 = case when month(YearMonth) = 6 then Projection_Month else 0 end,
Q3 = case when month(YearMonth) = 9 then Projection_Month else 0 end,
Q4 = case when month(YearMonth) = 12 then Projection_Month else 0 end
FROM Table1
WHERE
year(YearMonth) <= 2010
Hope, it can enlighten you :)
Regards,
fritz
Note: I haven't test the query, but i'm pretty sure it will work :)