在没有 ISNULL() 的情况下使用 SUM() 是否安全 [英] Is it safe to use SUM() without ISNULL()

查看:60
本文介绍了在没有 ISNULL() 的情况下使用 SUM() 是否安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力提高 SP 的性能.我对 SUM 和 ISNULL 有疑问.当我总结一列时,我应该使用 ISNULL 吗?在没有 ISNULL 的情况下使用 SUM() 是否安全.我的例子如下

I am trying to hence the performance of an SP. I have a doubt in my mind about SUM and ISNULL. When I sum up a column, should I use ISNULL? Is it SAFE to use SUM() without ISNULL. My example is below

SUM(ISNULL(COL1,0))

由于 ISNULL 成本很高,我打算使用 SUM 没有 ISNULL,如下所示

Since ISNULL costs a lot, I intend to use SUM without ISNULL like below

SUM(COL1)

我做了一些小测试,但看不到结果

I did some small tests and I couldnt see results

推荐答案

是的,很安全.您可以在不处理 NULL 值的情况下使用 Sum.你也可以检查一下.

Yes its safe . You can use Sum without handling NULL Value. You can also check that.

你也可以这样使用.

ISNULL(SUM(COL1),0).

ISNULL(SUM(COL1),0).

返回表达式中所有值的总和,或仅返回 DISTINCT 值.SUM 只能用于数字列.空值被忽略.

Returns the sum of all the values, or only the DISTINCT values, in the expression. SUM can be used with numeric columns only. Null values are ignored.

参考:https://msdn.microsoft.com/en-IN/library/ms187810.aspx

这篇关于在没有 ISNULL() 的情况下使用 SUM() 是否安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆