sql server - (Un)pivoting tables on SQL -


i'm trying create matrix historical data parameters have in table. matter is, when try pivot it, won't work. using following code

    select concept,         [1] '1993',          <...>,         [23] '2015'             (select concept, year(begin_date) year, value          params p with(nolock)) st     pivot     (         sum(value)         year in ([1], <...>, [23])     ) pt 

will return nothing matrix full of null values. on other hand, i've got correct values using other query

    select pt.year 'year',          [1],          <...>,         [38]              (select concept, year(begin_date) year, value         parameters p with(nolock)) st     pivot     (         sum(value)         concept in ([1], <...>, [38])     ) pt 

but columns , rows supposed other way around. cause of situation? how solved? in advance

you have:

year in ([1], <...>, [23]) 

this supposed be

year in ([1993], <...>, [2015]) 

and of course same columns in select part too:

select concept,     [1993],      <...>,     [2015] 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -