Предполагается, что вы используете SQL Server 2005 выше
DECLARE @code TABLE (Code VARCHAR(20), Product VARCHAR(100))
INSERT INTO @code (Code , Product)
VALUES ('AA','Prod A'),('CC','Prod C'),('CC','Prod C1')
;WITH cc AS
(
SELECT Code, COUNT(*) AS CodeCount
FROM @code
GROUP BY Code
)
SELECT
CASE WHEN cc.CodeCount = 1 THEN c.Code
ELSE c.Code + CAST(ROW_NUMBER() OVER ( PARTITION BY c.Code ORDER BY c.Product) AS VARCHAR(10))
END AS Code,
c.Product
FROM @code c
INNER JOIN cc
ON c.Code = cc.Code