I dont know whether your expected output is correct or not but as per your sample data and your descriptionI think you want to get the count of add of different userid and want to show total also in row to column format try this - DECLARE @User AS TABLE ( userid int, [add] varchar(10) )INSERT INTO @UserSELECT '1','aaa'UNION ALLSELECT '1','aaa'UNION ALLSELECT '1','aaa'UNION ALLSELECT '1','bbb'UNION ALLSELECT '2','aaa'UNION ALLSELECT '2','bbb'UNION ALLSELECT '1','ccc'SELECT UserID, [add aaa], [add bbb], [add ccc], [add aaa]+[add bbb]+[add ccc] AS Total FROM (SELECT UserID, 'add ' + [add] [add] FROM @User) APIVOT( COUNT([add]) FOR [add] IN ([add aaa], [add bbb], [add ccc]) ) P
Vaibhav TIf I cant go back, I want to go fast...