title: Combine multiple rows into 1 - Update table
body: <p>I need to combine rows in my table;  dvsAIPGroupID’s:  8 &amp; 73 are being combined into just 8. I want to sum the values for hedges, aiptotal, and value and group by the rest of the columns.</p>
  <p>This Table
  <a href="https://i.stack.imgur.com/jDu6B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jDu6B.png" alt="enter image description here" /></a></p>
  <p>Becomes this:
  <a href="https://i.stack.imgur.com/cHURj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cHURj.png" alt="enter image description here" /></a></p>
  <p>I can take a 2 step approach.</p>
  <ul>
  <li>First, update the dvsgroup_id = 8 and dvsAIPGroup_Name = DOM</li>
  <li>Second, I need to group by and sum the Hedges, AIP Total, and Value.</li>
  </ul>
  <p>I am not sure how to update the second step.</p>
  <p>It will be a one-time change and below would be the select statement which includes all my fields.</p>
  <pre><code>SELECT GasYearName, GasYear,dvsAIPGroup_ID, dvsAIPGroup_Name, dvsInstrumentType_Descript,
         dvsRegion_ID,dvsRegion_Name, dvsSuperRegion_Name, sum (Hedges) AS Hedges, sum (AIPTotal) AS AIPTotal, sum (Value) AS Value, AsOfDate
  FROM AIPBalance_WeeklySnapshot
  WHERE dvsAIPGroup_ID IN (860,1073)
  AND AsOfDate &gt;= '6/05/2020'
  GROUP BY GasYearName, GasYear,dvsAIPGroup_ID, dvsAIPGroup_Name, dvsInstrumentType_Descript,
         dvsRegion_ID,dvsRegion_Name, dvsSuperRegion_Name, Hedges, AIPTotal, Value, AsOfDate
  </code></pre>
  <p>I created a set of sample data:</p>
  <pre><code>IF NOT EXISTS (
      select * from sysobjects where name='AIPBalance_WeeklySnapshot' and xtype='U'
  ) CREATE TABLE AIPBalance_WeeklySnapshot (
      [GasYearName] NVARCHAR(10),
      [GasYear] INT,
      [dvsAIPGroup_ID] INT,
      [dvsAIPGroup_Name] NVARCHAR(4),
      [dvsInstrumentType_Descript] NVARCHAR(2),
      [dvsRegion_ID] INT,
      [dvsRegion_Name] NVARCHAR(3),
      [dvsSuperRegion_Name] NVARCHAR(2),
      [Hedges] NVARCHAR(4),
      [AIPTotal] INT,
      [Value] INT,
      [AsOfDate] DATETIME
  );
  INSERT INTO AIPBalance_WeeklySnapshot VALUES
      (N'GY ''20/''21',2020,8,N'DOM ',N'T ',3,N'NW ',N'W ',N'NULL',-12,-12,'2020-06-05 00:00:00'),
      (N'GY ''20/''21',2020,73,N'ROC ',N'T ',3,N'NW ',N'W ',N'NULL',0,0,'2020-06-05 00:00:00'),
      (N'GY ''21/''22',2021,73,N'ROC ',N'T ',3,N'NW ',N'W ',N'NULL',-11,-11,'2020-06-05 00:00:00'),
      (N'GY ''22/''23',2022,73,N'ROC ',N'T ',3,N'NW ',N'W ',N'NULL',-49,-49,'2020-06-05 00:00:00'),
      (N'GY ''20/''21',2020,8,N'DOM ',N'T ',3,N'NW ',N'W ',N'28',-12,0,'2020-06-12 00:00:00'),
      (N'FY ''20/''21',2020,73,N'ROC ',N'T ',3,N'NW ',N'W ',N'NULL',0,0,'2020-06-12 00:00:00'),
      (N'GY ''21/''22',2021,73,N'ROC ',N'T ',3,N'NW ',N'W ',N'NULL',-11,-11,'2020-06-12 00:00:00'),
      (N'GY ''22/''23',2022,73,N'ROC ',N'T ',3,N'NW ',N'W ',N'NULL',-49,-49,'2020-06-12 00:00:00'),
      (N'GY ''20/''21',2020,8,N'DOM ',N'T ',3,N'NW ',N'W ',N'28',63,0,'2020-06-19 00:00:00'),
      (N'GY ''20/''21',2020,73,N'ROC ',N'T ',3,N'NW ',N'W ',N'NULL',0,0,'2020-06-19 00:00:00'),
      (N'GY ''21/''22',2021,8,N'DOM ',N'T ',3,N'NW ',N'W ',N'NULL',-16,-16,'2020-06-19 00:00:00'),
      (N'GY ''21/''22',2021,73,N'ROC ',N'T ',3,N'NW ',N'W ',N'NULL',-11,-11,'2020-06-19 00:00:00'),
      (N'GY ''22/''23',2022,73,N'ROC ',N'T ',3,N'NW ',N'W ',N'46',-49,-30,'2020-06-19 00:00:00'),
      (N'GY ''20/''21',2020,8,N'DOM ',N'T ',3,N'NW ',N'W ',N'NULL',63,0,'2020-06-26 00:00:00'),
      (N'GY ''20/''21',2020,73,N'ROC ',N'T ',3,N'NW ',N'W ',N'NULL',0,0,'2020-06-26 00:00:00'),
      (N'GY ''21/''22',2021,8,N'DOM ',N'T ',3,N'NW ',N'W ',N'NULL',-16,-16,'2020-06-26 00:00:00'),
      (N'GY ''21/''22',2021,73,N'ROC ',N'T ',3,N'NW ',N'W ',N'NULL',-11,-11,'2020-06-26 00:00:00'),
      (N'GY ''22/''23',2022,73,N'ROC ',N'T ',3,N'NW ',N'W ',N'46',-49,-30,'2020-06-26 00:00:00');
  </code></pre>
  <p>Thanks for any help!</p>