sql - Without PIVOT, display data where GROUP BY column are the column names -


i have data looks following:

name    date         hr     min    amt joe     20150320     08     00     5 joe     20150320     08     15     3 carl    20150320     09     30     1 carl    20150320     09     45     2 ray     20150320     13     00     8 ray     20150320     13     30     6 

a simple group [name], [date], [hr] display total hour each salesman.

without using pivot or dynamic sql, how can display data hours columns? pivot need detail each hour, if data above data, there 3 columns data (8, 9, 13), , 21 empty columns.

the reason want because create ssrs report columns hours. unfortunately, can't use matrix because can't sort column detail (ie. click on "8" , display smallest largest); i've confirmed limitation ms expert.

so appreciated. have sql server 2008 r2. thanks.

select name           ,[date]       ,sum(case when hr = '00' amt end) [00]       ,sum(case when hr = '01' amt end) [01]       ,sum(case when hr = '02' amt end) [02]       ,sum(case when hr = '03' amt end) [03]       ,sum(case when hr = '04' amt end) [04]       ,sum(case when hr = '05' amt end) [05]       ,sum(case when hr = '06' amt end) [06]       ,sum(case when hr = '07' amt end) [07]       ,sum(case when hr = '08' amt end) [08]       ,sum(case when hr = '09' amt end) [09]       ,sum(case when hr = '10' amt end) [10]       ,sum(case when hr = '11' amt end) [11]       ,sum(case when hr = '12' amt end) [12]       ,sum(case when hr = '13' amt end) [13]       ,sum(case when hr = '14' amt end) [14]       ,sum(case when hr = '15' amt end) [15]       ,sum(case when hr = '16' amt end) [16]       ,sum(case when hr = '17' amt end) [17]       ,sum(case when hr = '18' amt end) [18]       ,sum(case when hr = '19' amt end) [19]        ,sum(case when hr = '20' amt end) [20]       ,sum(case when hr = '21' amt end) [21]       ,sum(case when hr = '22' amt end) [22]       ,sum(case when hr = '23' amt end) [23] tablenname group name ,[date] 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -