简体   繁体   English

需要有关SSRS SPLIT功能的帮助

[英]Need Help on SSRS SPLIT function

Hi All I need your advice, 大家好我需要你的建议,

1) I have a dynamic string which changes each time. 1)我有一个动态字符串,每次都会改变。

for example today the string will be "ItemA,ItemB,ItemC" and tomorrow it will be "itemA,ItemB" only. 例如,今天字符串将是"ItemA,ItemB,ItemC" ,明天它将只是"itemA,ItemB"

2) I have an SSRS report which has 3 columns 2)我有一份包含3列的SSRS报告

3) I want to split this string "ItemA,ItemB,ItemC" and want to show split substrings in these 3 columns of ssrs table. 3)我想将此字符串"ItemA,ItemB,ItemC"并希望在ssrs表的这3列中显示拆分子字符串。 the Delimiter is "," (comma) 分隔符是"," (逗号)

4) I had used 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) everything works fine until my string is "ItemA,ItemB,ItemC" , 5)一切正常,直到我的字符串是"ItemA,ItemB,ItemC"

BUT WHEN MY STRING CHANGES TO "ItemA,ItemB" I am seeing "#Error" in the third column. 但是当我的STRING "ItemA,ItemB"我在第三列中看到"#Error"

I understood the error, for 我理解错误了

=Split("ItemA,ItemB,ItemC",",").GetValue(2) we don't have any value because the string now has only 2 values after applying split function. =Split("ItemA,ItemB,ItemC",",").GetValue(2)我们没有任何值,因为在应用split函数后,字符串现在只有2个值。

Is there any way i can avoid #Error in the third column. 有什么办法可以避免在第三列中出现#Error

NOTE: I have to compulsorily use 3 columns in the ssrs report. 注意:我必须在ssrs报告中强制使用3列。

I had tried using =Replace(Split("ItemA,ItemB",",").GetValue(2),"#Error","NULL") in the third column but that also wont worked. 我曾尝试在第三列中使用=Replace(Split("ItemA,ItemB",",").GetValue(2),"#Error","NULL") ,但这也无效。

This is similar to the divide by zero issue in using IIF statements. 这类似于使用IIF语句中的除零问题 The problem is that IIF is not an expression, it is a function with three parameters: 问题是IIF不是表达式,它是一个具有三个参数的函数:

IIF(Condition, ValueIfTrue, ValueIfFalse)

Accordingly, ALL parameters are evaluated BEFORE being passed to the function, which results in the error because the erroneous expression is still evaluated even when the condition should mean that it isn't. 因此,在传递给函数之前评估所有参数,这导致错误,因为即使条件应该意味着它不是,仍然评估错误表达。

I can't see a way to use the usual workaround tha solves the problem in the divide by zero case. 我无法看到一种方法来使用通常的解决方法来解决除零情况下的问题。 What we need is a real language that doesn't have this problem. 我们需要的是一种没有这个问题的真实语言。 Fortunately, this is availble in the form of custom code. 幸运的是,这可以通过自定义代码的形式获得。

Do the following: 请执行下列操作:

  • Right-click on an area of the report surface that has no report objects 右键单击报表表面中没有报表对象的区域
  • Select Report Properties 选择报告属性
  • Click on the Code tab 单击“代码”选项卡
  • Insert the following code: 插入以下代码:

     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 
  • Click OK and go back to the report 单击“确定”并返回到报告

  • Right-click on the cell you want the expression in and click Expression 右键单击要表达式的单元格,然后单击“表达式”
  • Insert the following expression: 插入以下表达式:

     =Code.ExtractCode(Fields!Combo.Value, 3) 

The value 3 is the "column" that you want to extract from the Combo field, so to get the second "column" you would use 2. If there isn't a column at that position, an empty string is returned. 值3是要从Combo字段中提取的“列”,因此要获取第二个“列”,您将使用2.如果该位置没有列,则返回空字符串。

如果名称返回错误,您可以将第3列的可见性更改为隐藏

You can append a dummy element and then split: 您可以附加一个虚拟元素然后拆分:

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.

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