This example shows only one unique value of year, so the unpivot is straightforward.
SELECT * FROM star1p UNPIVOT (Q1sales, Q2sales, Q3sales, Q1cogs, Q2cogs, Q3cogs) FOR yr IN ((Q101Sales, Q201Sales, Q301Sales, Q101Cogs, Q201Cogs, Q301Cogs) AS ‘2001’) Tmp;
Result:
country state yr Q1sales Q2sales Q3sales Q1cogs Q2cogs Q3cogs ------- ----- ---- -------- ------- ------- ------ ------ ------ Canada ON 2001 ? 10 ? ? 0 ? Canada BC 2001 ? ? 10 ? ? 0 USA NY 2001 45 ? ? 25 ? ? USA CA 2001 30 50 ? 15 20