Row and column total in dynamic pivot
问题 In SQL Server 2008, I have a table (tblStock) with 3 columns: PartCode (NVARCHAR (50)) StockQty (INT) Location (NVARCHAR(50)) some example data below: PartCode StockQty Location ......... ......... ......... A 10 WHs-A B 22 WHs-A A 1 WHs-B C 20 WHs-A D 39 WHs-F E 3 WHs-D F 7 WHs-A A 9 WHs-C D 2 WHs-A F 54 WHs-E How to create procedure to get the result as below? PartCode WHs-A WHs-B WHs-C WHs-D WHs-E WHs-F Total ........ ..... ..... ..... ...... ..... ..... ..... A 10 1 9 0 0 0 20 B 22 0 0 0