sql server - Pivot in Pivot Columns in SQL Query -


i new sql , learning writing quires. me. in advance.

actually geeting following resultant table using query

select *  (select case temp             when '0' 'temperature'             when '1' 'pulse rate/min'            when '2' 'respiration/min'             when '3' 'blood pressure'             when '4' 'urine'          end temp,         value,          convert(nvarchar(15),date,103) date,        concat(case time                   when '0' '2'                   when '1' '6'                   when '2' '10'                end,' ',               case ampm                   when '0' 'am'                   when '1' 'pm'                end)[tim] hms_chart_clinical status = '0' , ipno='21460') s pivot(max(value) [date] in ([07/11/2016],[08/11/2016])) datapivot pivot(max(tim) [tim] in ([2 am],[6 am],[10 am],[2 pm],[6 pm],[10 pm])) datapivot 

image

but need bellow resultant table.

image2

you cant have table. best can create columns instead , add aditional header in ui.

 07/11/2016 02:00  07/11/2016 06:00  07/11/2016 10:00  07/11/2016 02:00 pm  07/11/2016 06:00 pm  07/11/2016 10:00 pm  08/11/2016 02:00  08/11/2016 06:00  08/11/2016 10:00  08/11/2016 02:00 pm  08/11/2016 06:00 pm  08/11/2016 10:00 pm 

so change query

concat(convert(nvarchar(15),date,103) date,        case time               when '0' '2'               when '1' '6'               when '2' '10'         end,' ',        case ampm               when '0' 'am'               when '1' 'pm'         end) [tim] 

and use single pivot

pivot(max(tim) [tim] in ([07/11/2016 02 am],                              [07/11/2016 06 am],                              [07/11/2016 10 am],                              [07/11/2016 02 pm],                              [07/11/2016 06 pm],                              [07/11/2016 10 pm]) .....) datapivot 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -