Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

pivot returns 7 rows instead of 1 for pivot on day name

$
0
0

Hi.  We run 2012 enterprise and the following pivot is returning 7 rows per dept instead of 1 ...

select dept,[Mon],[Tue],[Wed],[Thu],[Fri],[Sat],[Sun]
from #resultset  
pivot
(
sum(calc) for [datename] in ([Mon],[Tue],[Wed],[Thu],[Fri],[Sat],[Sun])
) as pvt

order by dept

can someone help?  There are a couple of null values for [calc] in my table but my understanding is that shouldnt matter.   Instead of one row with 0.0,0.25,null,1.0,1.0,1.0,1.0 for dept A in cols Mon thru Fri, I'm getting this...

Dept              Mon            Tue          Wed          Thu         Fri           Sat        Sun

A                   0.0              null          null           null         null          null       null

A                   null              0.25         null           null...

A                   null              null          null            null...

A                   null              null          null            1.0....etc          


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>