Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Unisci più record in una riga in una tabella

SELECT SalesAgentId, SalesAgentName, SUM(SalesAmount) AS SalesAmount
  INTO #AggSales
  FROM Sales
 GROUP BY SalesAgentId, SalesAgentName;

TRUNCATE TABLE Sales;    

INSERT INTO Sales
SELECT * FROM #AggSales;

DROP TABLE #AggSales;