Data Structure transformation- MS server

by Harish Mohan   Last Updated August 17, 2018 06:06 AM

I kinda stuck at transforming the data structure, Please help! This is what i have so far,

SELECT t0._id, t0.Category, MONTH(t0.TranDate) AS MONTHS, sum(t0.TranAmount) AS trans_total, 
                count(t0._id) AS trans_count, t0.TranBaseType

FROM [CreditSense].[dbo].[Transaction] AS t0
WHERE t0.TranDate IS NOT NULL
GROUP BY t0._id, t0.Category, MONTH(t0.TranDate), t0.Time_Of_Day, t0.TranBaseType
ORDER BY t0._id, t0.Category; 

I get this following out put enter image description here

But What i really want is some thing like this, enter image description here

This is just an illustration of the real data set. If you notice I names the columns based on the instances of the various combination of categorical variables. I really what this done automatically, like creating and naming the new columns. Please HELP!

Tags : sql-server


Related Questions


creating index on big table(s)

Updated September 03, 2018 18:06 PM

Linked Server Error on SQL Agent Job

Updated March 16, 2016 08:02 AM