entonces no viste el que te puse.......
Código SQL:
Ver originalSELECT T0.DocNum,T0.[CardCode], T0.[DocTotal] AS 'TOTAL EN BS' ,SUM(T1.[Quantity]) AS 'TOTAL' INTO #temp FROM ORPD T0 INNER JOIN RPD1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[DocDate] >='20130101' AND T0.[DocDate] <= '20130125'
GROUP BY T0.DocNum,T0.[CardCode],T0.[DocTotal]
ORDER BY T0.[CardCode]
SELECT num,num_doc,t1.codigo_doc,total_bs,total FROM(
SELECT ROW_NUMBER() OVER(partition BY codigo_doc ORDER BY codigo_doc) AS rn, num,num_doc,codigo_doc FROM #temp) AS t1
LEFT JOIN (SELECT codigo_doc,SUM(total_bs) total_bs,SUM(total) total FROM #temp GROUP BY codigo_doc) AS t2 ON (t1.codigo_doc=t2.codigo_doc AND t1.rn=1)
WHERE rn=1