简体   繁体   English

SSRS简单嵌套的IIF条件?

[英]SSRS simple nested IIF condition?

Please have a look at the below expression 请看下面的表达式

="Active : " & IIF(Parameters!lsSSelect_Active_Type_s_.Value = "FXNULL","ALL",
 iif(Parameters!lsSSelect_Active_Type_s_.Value=1,"Active",   
 iif(Parameters!lsSSelect_Active_Type_s_.Value=2,"Inactive","N/A")))

Now user have 3 options, 1, 2 or FXNULL. 现在用户有3个选项,1、2或FXNULL。 1 and 2 can display Active and Inactive correctly but when user select "FXNULL", it's throwing error. 1和2可以正确显示“活动”和“不活动”,但是当用户选择“ FXNULL”时,将引发错误。

The Value expression for the textrun contains an error: Input string was not in a correct format

Now in order to do a testing to make sure the comparison between FXNULL working fine, I tried the below expression and working fine 现在,为了进行测试以确保FXNULL之间的比较工作正常,我尝试了以下表达式并正常工作

="Active : " & IIF(Parameters!lsSSelect_Active_Type_s_.Value = "FXNULL","ALL","N/A")

What's wrong with the first expression? 第一个表达式有什么问题?

Add quotes on your numeric checks and it will run without errors 在数字检查中添加引号,它将正确运行

="Active : " & IIF(Parameters!lsSSelect_Active_Type_s_.Value = "FXNULL","ALL",
 iif(Parameters!lsSSelect_Active_Type_s_.Value="1","Active",   
 iif(Parameters!lsSSelect_Active_Type_s_.Value="2","Inactive","N/A")))

The reason this happens is because Iif evaluates all expressions and you have both numeric and string comparisons. 发生这种情况的原因是因为Iif计算所有表达式,并且您同时具有数字和字符串比较。

Also I would suggest the use of Switch instead of nested Iif to make your code more readable 我也建议使用Switch而不是嵌套的Iif,以使您的代码更具可读性

="Active : " & 
Switch(Parameters!lsSSelect_Active_Type_s_.Value = "FXNULL","ALL",
Parameters!lsSSelect_Active_Type_s_.Value="1","Active",   
Parameters!lsSSelect_Active_Type_s_.Value="2","Inactive",
True,"N/A"
)

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

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