简体   繁体   English

在SSRS表达式中使用分割

[英]Use Split in SSRS Expression

I've value like 100 - XYZ in dropdown list of SSRS Report. 我在SSRS报表的下拉列表中输入了100 - XYZ值。

I want to show only XYZ in one of the Textbox. 我只想在其中一个文本框中显示XYZ

I've used Split function like below, 我已经使用了如下的Split函数,

在此处输入图片说明

=IIF(Parameters!Name.Value <> "",
 "For Name" + Replace(Split(Parameters!Name.Value, "-").GetValue(1)," ", ""),
 "For All Names")

Above example works fine, but when it goes to else case it always throwing error. 上面的例子很好用,但是在其他情况下,总是抛出错误。

Can you please tell me what's wrong with this expression? 您能告诉我这个表达方式有什么问题吗? Or anything wrong with my expression? 还是我的表情有问题? Especially it is showing red line below (1) but as I said before it is working fine. 特别是它在(1)下显示红线,但正如我之前所说的那样,它工作正常。

Note: I have also tried .GetValue(1) recently but no success. 注意: 最近我也尝试了.GetValue(1)但没有成功。

As Jonnus has mentioned in comment, 正如Jonnus在评论中提到的那样,

It might be showing the error as there is a problem elsewhere in the expression , not just the False part. 由于expression其他地方(不仅是False部分)存在问题,可能显示了错误。 SSRS evaluates the entire expression before executing it , so if there is a problem anywhere it will throw #Error SSRS在执行整个表达式之前先对其求值 ,因此,如果任何地方有问题,它将抛出#Error

I found the alternate solution to achieve my expected result. 我找到了替代解决方案来达到我的预期结果。

=IIF(Parameters!Name.Label = "All",
"For All Names",
"For Name " + Replace(Right(Parameters!Name.Label,
Len(Parameters!Name.Label) - InStr(Parameters!Name.Label, "-"))," ",""))

I tried so many times with Split but I always got failed. 我在Split尝试了很多次,但总是失败。 If someone has idea to solve this with Split then it would be great. 如果有人想用Split解决这个问题,那就太好了。 Please share your view. 请分享您的看法。 Thanks Jonnus for your quick response. 感谢Jonnus的快速回复。

You appear to be trying to retrieve all the characters after the - in the original string. 您似乎正在尝试检索原始字符串中-之后的所有字符。 Rather than doing a SPLIT it would be easier to understand and maintain if you used RIGHT as follows 如果您按以下方式使用RIGHT,则比执行SPLIT更容易理解和维护

=iif(Parameters!Name.Value <> "",
 "For Name " & Right(Parameters!Name.Value, 
                     Instr(Parameters!Name.Value, " - ") -1),
 "For All Names")

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

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