简体   繁体   English

错误条件下SSRS表达式中的错误

[英]Error in SSRS expression for false condition

I want to generate my string in the following format: 我想以以下格式生成我的字符串:

Vancouer should be displayed as -> ( V) anc-ouer Vancouer应该显示为-> ( V) anc-ouer
Roberts Cut-Off Road -> Roberts Cu(tO) ff-Road ... etc So for the last 4 charaters I am using: Roberts Cut-Off Road -> Roberts Cu(tO) ff-Road ...等等因此,对于我使用的最后四个字符:

Right(Fields!NAME.Value, 4)

for the middle portion I am using IIF : 对于中间部分,我正在使用IIF:

IIF(Len(Fields!NAME.Value) < 10, 
Left(Fields!NAME.Value,. 
(Len(Fields!NAME.Value)-7)), 
 Mid(Fields!NAME.Value,Len(Fields!NAME.Value)-9,3))

But the above IIF condition gives me #Error whenever the length is less than 10. What could be the possible solution for it? 但是上述IIF条件在长度小于10时给了我#Error。可能的解决方案是什么? Or its better if I could know the expression to generate the complete format in easiest way possible. 如果我能知道该表达式以最简单的方式生成完整格式,则更好。

Even if you have the condition to check for 10 characters SSRS still evaluates the false part which is why you are getting the error, this is normally encountered when attempting to avoid divide by zero errors. 即使您有条件检查10个字符,SSRS仍会评估错误部分,这就是您得到错误的原因,但是在尝试避免除以零错误时通常会遇到这种情况。 more info here 更多信息在这里

divide by zero/null workaround 除以零/空解决方法

another article 另一篇文章

To compensate for the issue that RegBes mentioned, use an additional IIF to workaround the error for the false part of the initial IIF. 为了补偿RegBes提到的问题,请使用其他IIF来解决初始IIF错误部分的错误。

IIF(Len(Fields!NAME.Value) < 10, 
        Left(Fields!NAME.Value, Len(Fields!NAME.Value) - 7), 
        Mid(Fields!NAME.Value, Len(Fields!NAME.Value) - IIF(Len(Fields!NAME.Value) < 10, 0, 9), 3) 
    )

This will subtract 0 if the LEN is less than 10. The first IIF will ensure that this code doesn't display a value but worksaround the issue of the IIF evaluating the TRUE and FALSE parts of the IIF. 如果LEN小于10,则将减去0。第一个IIF将确保该代码不显示值,但可以解决IIF评估IIF的TRUE和FALSE部分的问题。

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

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