请看下面的表达
="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")))
现在用户有3个选项,1,2或FXNULL。 1和2可以正确显示Active和Inactive但是当用户选择“FXNULL”时,它会抛出错误。
The Value expression for the textrun contains an error: Input string was not in a correct format
现在为了进行测试以确保FXNULL
之间的比较工作正常,我尝试了以下表达式并正常工作
="Active : " & IIF(Parameters!lsSSelect_Active_Type_s_.Value = "FXNULL","ALL","N/A")
第一个表达式出了什么问题?
答案 0 :(得分:2)
在数字检查上添加引号,它将无误运行
="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")))
发生这种情况的原因是因为Iif会评估所有表达式,并且您同时进行数字和字符串比较。
另外,我建议使用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"
)