title: SQL Newbie Needs Assistance w/ Query
body: <p>Below is what I am trying to do in SQL Server 2012.  I want to Update Table 2 with the % of total that each AMT value is to the total in Table 1.  But the denominator to get the % should only be the total of the rows that have the same MasterDept.  I can use this SELECT query to get the correct percentages when I load the table with only one MasterDept but do not know how to do it when there are multiple MasterDept.  The first 2 columns in each table are identical both in structure and the data within the columns.</p>
  
  <pre><code>SELECT ABCID,
       [AMT%] = ClientSpreadData.AMT/CONVERT(DECIMAL(16,4),(SELECT SUM(ClientSpreadData.AMT) 
       FROM ClientSpreadData))
  FROM ClientSpreadData
  </code></pre>
  
  <p>Table data</p>
  
  <pre><code>TABLE 1 (MasterDept varchar(4), ABCID varchar(20), AMT INT)
  Sample Data (4700, 1, 25),
              (4300, 2, 30),
              (4700, 3, 50),
              (4300, 4, 15)
  
  TABLE 2 (MasterDept varchar(4), ABCID varchar(20), [AMT%] INT)
  Sample Data (4700, 1, AMT%)
  </code></pre>
  
  <p>AMT% should equal AMT / SUM(AMT).  SUM(AMT) should only be summing the values where the MasterDept on Table 1 matches the MasterDept from the record on Table 2.   </p>
  
  <p>Does that make sense? </p>