SQL: sum 3 columns when one column has a null value?

前端 未结 9 2037
北恋
北恋 2020-12-05 09:37
SELECT 
    sum(TotalHoursM)
          + (TotalHoursT)
          + (TotalHoursW)
          + (TotalHoursTH)
          + (TotalHoursF) 
          AS TOTAL
FROM LeaveR         


        
相关标签:
9条回答
  • 2020-12-05 09:58

    If you want to avoid the null value use IsNull(Column, 1)

    0 讨论(0)
  • 2020-12-05 10:05

    You can also use nvl(Column,0)

    0 讨论(0)
  • 2020-12-05 10:06

    You can use ISNULL:

    ISNULL(field, VALUEINCASEOFNULL)
    
    0 讨论(0)
提交回复
热议问题