title: SQL Union Count to Sum Data
body: <p>I have a bit of a complex query .... I need to do an update statement on the summation of two union-ed SQL queries (problem is the data in the queries isn't numeric so i'm counting rows instead of summing values) but I then need to sum those rows. </p>
  
  <pre><code>UPDATE  #LT_Actuals_TEMP 
  SET     pCount =  h.countPerfs
  FROM    (
  select count(distinct c.perf_description) as countPerfs, b.program, b.Prog_id
  from #LT_Actuals_TEMP TableP
  where       a.Performances = 'Y' and a.current_inactive = 0
  group by    b.Program, b.Prog_id
  union 
  select  distinct count(p.perf_code) as countPerfs, x.value, b.Prog_id
  from    T_PERF p    
  where   x.content_type = 23
  group by  x.value, b.Prog_id
  ) h where h.Prog_id = #LT_Actuals_TEMP.program_id
  </code></pre>
  
  <p>the first query data comes back as such</p>
  
  <pre><code>countPerfs   program    Prog_id
  7            Name       31
  </code></pre>
  
  <p>and second query comes back as </p>
  
  <pre><code>countPerfs   program    Prog_id
  1            Name       31
  </code></pre>
  
  <p>what I need <code>pCount</code>  to be set to at the end of the day is 8</p>
  
  <p>Expected results<br>
  when I do <code>select * from #LT_Actuals_TEMP</code> 
  I see the value
  8 for the Program Name, Id 31</p>