[英]I need help making the code split the sentence. where would I input the split function in my code
[英]Need Help on SSRS SPLIT function
大家好我需要你的建议,
1)我有一个动态字符串,每次都会改变。
例如,今天字符串将是"ItemA,ItemB,ItemC"
,明天它将只是"itemA,ItemB"
。
2)我有一份包含3列的SSRS报告
3)我想将此字符串"ItemA,ItemB,ItemC"
并希望在ssrs表的这3列中显示拆分子字符串。 分隔符是","
(逗号)
4)我用过
=Split("ItemA,ItemB,ItemC",",").GetValue(0) in the first column of the report
=Split("ItemA,ItemB,ItemC",",").GetValue(1) in the second column of the report
=Split("ItemA,ItemB,ItemC",",").GetValue(2) in the third column of the report
5)一切正常,直到我的字符串是"ItemA,ItemB,ItemC"
,
但是当我的STRING "ItemA,ItemB"
我在第三列中看到"#Error"
。
我理解错误了
=Split("ItemA,ItemB,ItemC",",").GetValue(2)
我们没有任何值,因为在应用split函数后,字符串现在只有2个值。
有什么办法可以避免在第三列中出现#Error
。
注意:我必须在ssrs报告中强制使用3列。
我曾尝试在第三列中使用=Replace(Split("ItemA,ItemB",",").GetValue(2),"#Error","NULL")
,但这也无效。
这类似于使用IIF语句中的除零问题 。 问题是IIF不是表达式,它是一个具有三个参数的函数:
IIF(Condition, ValueIfTrue, ValueIfFalse)
因此,在传递给函数之前评估所有参数,这导致错误,因为即使条件应该意味着它不是,仍然评估错误表达。
我无法看到一种方法来使用通常的解决方法来解决除零情况下的问题。 我们需要的是一种没有这个问题的真实语言。 幸运的是,这可以通过自定义代码的形式获得。
请执行下列操作:
插入以下代码:
Public Function ExtractCode(Combined As String, Position As Integer) As String if (Split(Combined, ",").Length >= Position) Then Return Split(Combined, ",").GetValue(Position-1) Else Return "" End If End Function
单击“确定”并返回到报告
插入以下表达式:
=Code.ExtractCode(Fields!Combo.Value, 3)
值3是要从Combo字段中提取的“列”,因此要获取第二个“列”,您将使用2.如果该位置没有列,则返回空字符串。
如果名称返回错误,您可以将第3列的可见性更改为隐藏
您可以附加一个虚拟元素然后拆分:
yourText = "ItemA,ItemB"
item0 = Split(yourText & ",", ",").GetValue(0)
item1 = Split(yourText & ",", ",").GetValue(1)
item2 = Split(yourText & ",", ",").GetValue(2)
item0 = ItemA
item1 = ItemB
item2 =
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.