[Solved] How do I pivot with hour format(HH:HourNumber)?
First of all create a temp table to use it in 3 places – Select columns for pivot, Replace null with zero and inside pivot. SELECT DISTINCT SUM(ORDERTOTAL) OVER(PARTITION BY CAST(ORDERTIME AS DATE),DATEPART(HH,ORDERTIME)) [TOTAL], CONVERT(varchar, CAST(ORDERTIME AS datetime), 103) [DATE], DATEPART(HH,ORDERTIME) [HOUR], ‘HH:’+CAST(DATEPART(HH,ORDERTIME) AS VARCHAR(3)) [HOURCOL] INTO #NEWTABLE FROM ORDERTBL ORDER BY DATEPART(HH,ORDERTIME) Now declare … Read more