Как бы я это сделал, используя STUFF
:
WITH VTE AS(
SELECT *
FROM (VALUES(1,'xxx AA',10),
(2,'yyy B',20),
(3,'zzz AA',11),
(4,'xxx B',20),
(5,'kkk C',30)) V(ID,[Name],[Value]))
SELECT ROW_NUMBER() OVER (ORDER BY N.R) AS ID,
N.R AS [Name],
SUM([Value]) AS [Value]
FROM VTE V
CROSS APPLY (VALUES(STUFF(V.[Name],1,CHARINDEX(' ',V.[Name]),''))) N(R)
GROUP BY N.R
ORDER BY N.R;