I have a scenario where I need to represent data being returned by converting the Day column from being in a row format to being in a column format. I believe that PIVOT can be used here but I've been unsuccessful so far and need to now turn to professionals.
Below is the script that I am returning. I need the day values to be as columns and not as rows
SELECT TOP (100)
PERCENT CASE Channel WHEN 'DT - Distributors' THEN '[DT ] - Distributors' WHEN 'FN - Furniture' THEN '[FN ] - Furniture' WHEN 'IC - Inter Company' THEN '[IC ] - Inter Company'
WHEN 'IN - Independent' THEN '[IN ] - Independent' WHEN 'MD - Mass Discounter' THEN '[MD ] - Mass Discounter' WHEN 'OC - OTHER CONSUMER' THEN '[OC ] - OTHER CONSUMER'
WHEN 'PR - Power Retailers' THEN '[PR ] - Power Retailers' WHEN 'PS - Photo Specialist' THEN '[PS ] - Photo Specialist' WHEN 'SC - Sony Centre' THEN '[SC ] - Sony Centre' ELSE
'[UC ] - Unclassified' END AS Channel,
CASE Channel WHEN 'DT - Distributors' THEN '1' WHEN 'FN - Furniture' THEN '2' WHEN 'IC - Inter Company' THEN '3' WHEN 'IN - Independent' THEN '4' WHEN 'MD - Mass Discounter'
THEN '5' WHEN 'OC - OTHER CONSUMER' THEN '6' WHEN 'PR - Power Retailers' THEN '7' WHEN 'PS - Photo Specialist' THEN '8' WHEN 'SC - Sony Centre' THEN '8' ELSE '9' END
AS ChannelSort,
CASE CateGory WHEN 'AMC' THEN 'AMC' WHEN 'CTV' THEN 'CTV' WHEN 'GA' THEN 'GA' WHEN 'HA' THEN 'HA' WHEN 'NMWM' THEN 'NMWM' WHEN 'HT' THEN 'HT' WHEN 'HV' THEN
'HV' WHEN 'ME' THEN 'ME' ELSE 'OTH' END AS Category,
CASE CateGory WHEN 'AMC' THEN '1' WHEN 'CTV' THEN '2' WHEN 'GA' THEN '3' WHEN 'HA' THEN '4' WHEN 'NMWM' THEN '5' WHEN 'HT' THEN '6' WHEN 'HV' THEN '7' WHEN 'ME'
THEN '8' ELSE '9' END AS CategorySort, CAST(RIGHT(PhyYearMonth, 2) AS int) AS Day, SUM(GrossAmt) AS SalesAmt
FROM dbo.Daily_SalesSummary_RawData
GROUP BY Channel, CateGory, CAST(RIGHT(PhyYearMonth, 2) AS int)
ORDER BY ChannelSort, CategorySort
Any assistance would be greatly appreciated. Thanks