Вы пробовали что-то подобное?
DECLARE @Table TABLE(
CustomerID INT,
[Service] VARCHAR(MAX),
TransType VARCHAR(MAX),
SubTotal FLOAT,
Tax FLOAT,
NetTotal FLOAT
)
INSERT INTO @Table (CustomerID,[Service],TransType,SubTotal,Tax,NetTotal)
SELECT 106, 'A', 'CREDIT', 12.52, 0 , 12.52
INSERT INTO @Table (CustomerID,[Service],TransType,SubTotal,Tax,NetTotal)
SELECT 106, 'A', 'CREDIT', 10.07, 0 , 10.07
INSERT INTO @Table (CustomerID,[Service],TransType,SubTotal,Tax,NetTotal)
SELECT 106, 'B', 'CREDIT', 2, 0 , 2
INSERT INTO @Table (CustomerID,[Service],TransType,SubTotal,Tax,NetTotal)
SELECT 106, 'C', 'REMOTE', 5.99, 0 , 5.99
INSERT INTO @Table (CustomerID,[Service],TransType,SubTotal,Tax,NetTotal)
SELECT 106, 'C', 'CREDIT', 5.99, 0 , 5.99
INSERT INTO @Table (CustomerID,[Service],TransType,SubTotal,Tax,NetTotal)
SELECT 106, 'C', 'CREDIT', 3.99, 0.3 , 3.69
INSERT INTO @Table (CustomerID,[Service],TransType,SubTotal,Tax,NetTotal)
SELECT 106, 'C', 'CREDIT', 5.99, 0.3 , 5.69
INSERT INTO @Table (CustomerID,[Service],TransType,SubTotal,Tax,NetTotal)
SELECT 106, 'D', 'CREDIT', 5.99, 0 , 5.99
SELECT Pivots.CustomerID,
Pivots.[Service],
Pivots.Cash,
Pivots.[Check],
Pivots.Credit,
Pivots.[Remote],
Total.SumSubTotal,
Total.SumTax,
Total.SumNetTotal
FROM (
SELECT CustomerID,
[Service],
[Cash] Cash,
[Check] [Check],
[Credit] Credit,
[Remote] [Remote]
FROM (
SELECT CustomerID,
[Service],
TransType,
SubTotal
FROM @Table
) sub
PIVOT
(
SUM(SubTotal)
FOR [TransType] IN ([Cash],[Check],[Credit],[Remote])
) pvt
) Pivots INNER JOIN
(
SELECT CustomerID,
[Service],
SUM(SubTotal) SumSubTotal,
SUM(Tax) SumTax,
SUM(NetTotal) SumNetTotal
FROM @Table
GROUP BY CustomerID,
[Service]
) Total ON Pivots.CustomerID = Total.CustomerID
AND Pivots.[Service] = Total.[Service]