title: Creating SumIf function in SQL Server 2012
body: <p>I need some help building a SQL Server function that acts as a <code>SumIf</code> in Excel, for example </p>
  
  <pre><code>SumIF(Fees.Fee_Amount, Fees.Type ='Services' and Fees.Fee_Code = 'B01')
  </code></pre>
  
  <p>so the item that would be summed if it is a <code>Fees.Fee_Amount</code> and the where part is <code>Fees.Type ='Services'</code> and <code>Fees.Fee_Code = 'B01'</code></p>
  
  <p>Syntax would be <code>SumIf(TableName.ColumnName, Criteria)</code>, the function would return the total.</p>