Replacing NULL with 0 in a SQL server query

后端 未结 12 1230
情书的邮戳
情书的邮戳 2020-11-28 02:39

I have developed a query, and in the results for the first three columns I get NULL. How can I replace it with 0?

  Select c.rund         


        
12条回答
  •  臣服心动
    2020-11-28 03:14

    With coalesce:

    coalesce(column_name,0)
    

    Although, where summing when condition then 1, you could just as easily change sum to count - eg:

    count(case when c.runstatus = 'Succeeded' then 1 end) as Succeeded,
    

    (Count(null) returns 0, while sum(null) returns null.)

提交回复
热议问题