title: Can't figure out how sum(1) is working in this query
body: <p>So I am trying to combine to query's and to do that I need to figure out what is going on in this one. I'm still relatively new to sql server and I am forced to dive right into some complicated qrys and sometimes I get stuck on simple things like this. My problem is that the Sum(1) function is used and I'm not entirely sure how. Meaning I believe it is counting duplicates but I cannot tell based on what information it is doing so.</p>
  
  <p>this is the query</p>
  
  <pre><code>SELECT 
  qryReinsuranceDPA1.POLICY_NO, 
  qryReinsuranceDPA1.PHASE_CODE, 
  qryReinsuranceDPA1.SUB_PHASE_CODE, 
  qryReinsuranceDPA1.ProdType, 
  TotalDPA = Sum(case when [SumOfNetDefExtraAdj] Is Null then [SumOfNetDefPremiumAdj] else [SumOfNetDefPremiumAdj] + SumOfNetDefExtraAdj end), 
  Sum(1) AS Expr1
  FROM qryPolicyListforNYDefPRemAsset_Re RIGHT JOIN qryReinsuranceDPA1
  ON 
  qryReinsuranceDPA1.POLICY_NO = qryPolicyListforNYDefPRemAsset_Re.POLICY_NO AND 
  qryReinsuranceDPA1.PHASE_CODE= qryPolicyListforNYDefPRemAsset_Re.PHASE_CODE AND 
  qryReinsuranceDPA1.SUB_PHASE_CODE = qryPolicyListforNYDefPRemAsset_Re.SUB_PHASE_CODE 
  GROUP BY qryReinsuranceDPA1.POLICY_NO, 
  qryReinsuranceDPA1.PHASE_CODE, 
  qryReinsuranceDPA1.SUB_PHASE_CODE, 
  qryReinsuranceDPA1.ProdType
  --HAVING (((Sum(1))&lt;&gt;1))
  
  GO
  </code></pre>
  
  <p>And this is a small sample of what it produces (the actually results number around 77,000)</p>
  
  <pre><code>POLICY_NO    PHASE_CODE    SUB_PHASE_CODE    ProdType   TotalDPA       Expr1
  228433800    0             1                 TERM       282.324223     1
  228439200    0             1                 PERM       53.17048634    1
  228439200    6             1                 PERM       10.3805065     1
  228441500    0             1                 PERM       526.6883742    1
  228441500    0             2                 PERM       10.63320899    1
  228441700    0             1                 PERM       20.86247317    1
  228448100    0             1                 PERM       345.2117169    1
  228460200    0             1                 TERM       302.7574933    1
  228464900    0             1                 TERM       191.2597906    1
  228468000    0             1                 PERM       8445.190912    1
  228473600    0             1                 TERM       339.8413682    **2**
  228473800    0             1                 TERM       686.1766864    **2**
  228477200    0             1                 TERM       583.7580207    1
  228481200    0             1                 TERM       362.9472595    1
  228481200    0             2                 PERM       4.217792443    1
  228482500    0             1                 PERM       1894.303507    1
  228482500    1             1                 TERM       1312.183889    1
  228491600    0             1                 TERM       325.0796843    **2**
  228494400    0             1                 PERM       748.2710255    1
  228501000    0             1                 TERM       47.78070676    1
  228501100    0             1                 TERM       47.78070676    1
  228501300    0             1                 PERM       365.5651862    1
  228501300    0             2                 PERM       12.20547324    1
  228501300    1             1                 TERM       706.0961491    1
  228501300    1             2                 PERM       12.46769547    1
  228502000    0             1                 PERM       6562.164879    1
  228502000    0             2                 PERM       184.7741277    1
  </code></pre>
  
  <p>The right most column is the result of the Sum(1) and what I want to know is when and why does it produce a 2.</p>