在 SSRS 表达式中使用拆分
Use Split in SSRS Expression
我在 SSRS 报告的下拉列表中有 100 - XYZ
这样的值。
我只想在其中一个文本框中显示 XYZ
。
我使用了如下的 Split 函数,
=IIF(Parameters!Name.Value <> "",
"For Name" + Replace(Split(Parameters!Name.Value, "-").GetValue(1)," ", ""),
"For All Names")
上面的例子工作正常,但是当它进入其他情况时它总是抛出错误。
你能告诉我这个表达式有什么问题吗?还是我的表达有问题?特别是它在 (1)
下面显示红线,但正如我之前所说,它工作正常。
注意: 我最近也试过.GetValue(1)
,但是没有成功。
您似乎试图检索原始字符串中 -
之后的所有字符。如果您按如下方式使用 RIGHT,那么与其进行 SPLIT 相比,它会更容易理解和维护
=iif(Parameters!Name.Value <> "",
"For Name " & Right(Parameters!Name.Value,
Instr(Parameters!Name.Value, " - ") -1),
"For All Names")
正如 Jonnus 在评论中提到的,
It might be showing the error as there is a problem elsewhere in the expression
, not just the False
part. SSRS evaluates the entire
expression before executing it, so if there is a problem anywhere it
will throw #Error
我找到了实现预期结果的替代解决方案。
=IIF(Parameters!Name.Label = "All",
"For All Names",
"For Name " + Replace(Right(Parameters!Name.Label,
Len(Parameters!Name.Label) - InStr(Parameters!Name.Label, "-"))," ",""))
我用 Split
尝试了很多次,但总是失败。如果有人想用 Split
解决这个问题,那就太好了。请分享您的观点。感谢 Jonnus 的快速回复。
我在 SSRS 报告的下拉列表中有 100 - XYZ
这样的值。
我只想在其中一个文本框中显示 XYZ
。
我使用了如下的 Split 函数,
=IIF(Parameters!Name.Value <> "",
"For Name" + Replace(Split(Parameters!Name.Value, "-").GetValue(1)," ", ""),
"For All Names")
上面的例子工作正常,但是当它进入其他情况时它总是抛出错误。
你能告诉我这个表达式有什么问题吗?还是我的表达有问题?特别是它在 (1)
下面显示红线,但正如我之前所说,它工作正常。
注意: 我最近也试过.GetValue(1)
,但是没有成功。
您似乎试图检索原始字符串中 -
之后的所有字符。如果您按如下方式使用 RIGHT,那么与其进行 SPLIT 相比,它会更容易理解和维护
=iif(Parameters!Name.Value <> "",
"For Name " & Right(Parameters!Name.Value,
Instr(Parameters!Name.Value, " - ") -1),
"For All Names")
正如 Jonnus 在评论中提到的,
It might be showing the error as there is a problem elsewhere in the
expression
, not just theFalse
part. SSRS evaluates the entire expression before executing it, so if there is a problem anywhere it will throw#Error
我找到了实现预期结果的替代解决方案。
=IIF(Parameters!Name.Label = "All",
"For All Names",
"For Name " + Replace(Right(Parameters!Name.Label,
Len(Parameters!Name.Label) - InStr(Parameters!Name.Label, "-"))," ",""))
我用 Split
尝试了很多次,但总是失败。如果有人想用 Split
解决这个问题,那就太好了。请分享您的观点。感谢 Jonnus 的快速回复。