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

Column totals using PIVOT in SQL Server 2008 R2

$
0
0

Hi, How to calculate column totals using PIVOT in SQL Server 2008 R2. I would like to get column totals for each employee. Can this be done in T-SQL?

USE AdventureWorks2008R2
GO
SELECT VendorID, [250] AS Emp1, [251] AS Emp2, [256] AS Emp3, [257] AS Emp4, [260] AS Emp5
FROM 
(SELECT PurchaseOrderID, EmployeeID, VendorID
FROM Purchasing.PurchaseOrderHeader) p
PIVOT
(
COUNT (PurchaseOrderID)
FOR EmployeeID IN
( [250], [251], [256], [257], [260] )
) AS pvt
ORDER BY pvt.VendorID
GO
Thanks in advance..............

Viewing all articles
Browse latest Browse all 23857

Trending Articles



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