Creating SumIf function in SQL Server 2012

后端 未结 1 492
感情败类
感情败类 2020-12-17 18:46

I need some help building a SQL Server function that acts as a SumIf in Excel, for example

SumIF(Fees.Fee_Amount, Fees.Type =\'Services\' and F         


        
相关标签:
1条回答
  • 2020-12-17 19:27

    The simplest way would be to SUM a CASE clause, like so:

    SUM(CASE WHEN Fees.Type ='Services' and Fees.Fee_Code = 'B01'
             THEN Fees.Fee_Amount
        END) AS ColumnAlias,
    
    0 讨论(0)
提交回复
热议问题