SQL SERVER T-SQL Calculate SubTotal and Total by group
I am trying to add subtotal by group and total to a table. I've recreated the data using the following sample. DECLARE @Sales TABLE( CustomerName VARCHAR(20), LegalID VARCHAR(20), Employee VARCHAR(20), DocDate DATE, DocTotal Int, DueTotal Int ) INSERT INTO @Sales SELECT 'Jhon Titor','12345', 'Employee1','2015-09-01',1000,200 INSERT INTO @Sales SELECT 'Jhon Titor','12345', 'Employee1','2015-08-20',500,100 INSERT INTO @Sales SELECT 'Jhon Titor','12345', 'Employee1','2015-08-18',200,50 INSERT INTO @Sales SELECT 'Deli Armstrong','2345', 'Employee1','2015-09-17',2300,700 INSERT INTO @Sales SELECT