Home Convert Rows to columns using 'Pivot' in SQL Server
Reply: 0

Convert Rows to columns using 'Pivot' in SQL Server

user1212
1#
user1212 Published in June 25, 2018, 12:19 am

Well I guess I am really dense. I have read the stuff on MS pivot tables and I am still having problems getting this correct. I have seen some of you that seem to eat and sleep this stuff, so I just decided to sign-up and ask the question.

I have a temp table that is being created, we will say that column 1 is a Store number, and column 2 is a week number and lastly column 3 is a total of some type. Also the Week numbers are dynamic, the store numbers are static.

Store      Week     xCount
-------    ----     ------
102        1        96
101        1        138
105        1        37
109        1        59
101        2        282
102        2        212
105        2        78
109        2        97
105        3        60
102        3        123
101        3        220
109        3        87

I would like it to come out as a pivot table, like this:

Store        1          2          3        4        5        6....
----- 
101        138        282        220
102         96        212        123
105         37        
109

Store numbers down the side and weeks across the top.

Thanks for the help.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.335345 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO