Código SQL:
Ver originalCREATE TABLE #temp
(
codcliente VARCHAR(20),
idpedido INT,
nombrecliente VARCHAR(20)
)
INSERT INTO #temp VALUES ('000638' , 1741 , 'BBBBB BBBBB')
INSERT INTO #temp VALUES ('001357' , 1743 , 'AAAAA AAAAA')
INSERT INTO #temp VALUES ('001357' , 1744 , 'AAAAA AAAAA')
INSERT INTO #temp VALUES ('001343' , 1697 , 'CCCCC CCCCC')
SELECT * FROM(
SELECT COUNT(*) AS total, codcliente FROM #temp GROUP BY codcliente) AS t1
LEFT JOIN #temp AS t2 ON (t1.codcliente=t2.codcliente)
Resultado:
total codcliente codcliente idpedido nombrecliente
1 000638 000638 1741 BBBBB BBBBB
1 001343 001343 1697 CCCCC CCCCC
2 001357 001357 1743 AAAAA AAAAA
2 001357 001357 1744 AAAAA AAAAA