简体   繁体   English

SSRS 2008-处理除以NULL值

[英]SSRS 2008- Dealing with division by NULL Values

I am dividing Field_A by Field_B. 我将Field_A除以Field_B。 But the problem is that sometimes Field_A is NULL (doesn't have any value). 但是问题是有时Field_A为NULL(没有任何值)。 How can i check for that? 我该如何检查?

If it is Null, i guess the result should be 0 or Null. 如果为Null,我猜结果应该为0或Null。

Use an IIF (inline If statement) in the expression: 在表达式中使用IIF(内联If语句):

=IIF(<Condition>,<TruePart>,<FalsePart>)

=IIF(Field_A Is Nothing OR Field_B = 0, 0, Field_A/Field_B)

This way, you are making sure that Field_A is not null and Field_B is not zero, to also avoid divide by zero errors. 这样,您要确保Field_A不为null且Field_B不为零,以免除以零错误。

The Easiest Method is to simply add a very small value to potential null value/zero value So : 最简单的方法是将一个非常小的值简单地添加到潜在的空值/零值So中:

=IIF(Field_A Is Nothing OR Field_B = 0, 0, Field_A/( Field_B + .000001)) = IIF(Field_A为空或Field_B = 0、0,Field_A /(Field_B + .000001))

This will still give you 0 when the value is either null or zero, but will prevent the #error from showing up when the denominator is otherwise null or zero 如果值为null或零,这仍将为您提供0,但如果分母为null或零,则将防止显示#error。

Also : Be careful to make sure that your types are the same; 另外:请注意确保您的类型相同; meaning, if the data type of your Field_A is decimal or double, make sure that you cast the small amount .000001 to CDec(.000001) 意思是,如果Field_A的数据类型是十进制或双精度型,请确保将少量的.000001转换为CDec(.000001)

I have found that making sure that all types in your expression are the same is key to avoiding the #Error message 我发现确保表达式中的所有类型都相同是避免#Error消息的关键

Yes, I think what "Jammie F" has commented above is correct.If Field B is 0 then you will get Divide by zero error. 是的,我认为上面的“ Jammie F”评论是正确的。如果字段B为0,则将得到除以零的错误。 What you can use is:- 您可以使用的是:

iif(Field_B=0,0,Field_A/Field_B) iif(Field_B = 0,0,Field_A / Field_B)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM