数量不断变化的 SSRS 表达式拆分字符串

SSRS expression split string with changing quantities

我使用以下文章 (ssrs expression to split string possible?) 允许我以这种格式从 SQL 列中获取数据:

IMAGE01 IMAGE02 IMAGE03 (all these values are in one field)

并将其呈现在我的 SSRS 报告拆分中,因此它在报告单元格中显示为:

IMAGE01
IMAGE02
IMAGE03 

我面临的问题是 SQL 单元格中 IMAGExx 值的数量是完全随机的,SSRS 中是否有一种方法可以确定拆分字符串中有多少个值然后将正确的数量分成像上面那样的行?

现在我的表情是这样的(测试):

=(Split(Fields!something.Value, " ")).GetValue(0) & vbcrlf & (Split(Fields!something.Value, " ")).GetValue(2)

但我不知道给定字段中是否有 2 个值或 9 个值。

编辑:

下面的代码很棒,但在值之间给了我一个额外的新行:

IMAGE01

IMAGE02

IMAGE03

我认为您可以使用自定义代码来解决您的问题。

转到 Report 菜单,Report Properties / Code 选项卡并将此代码放入文本区域。

Public Function mySplit(ByVal my_field As String) As String
    Dim result As String = ""       
    If my_field is Nothing or my_field = "" Then
        Return result
    End If
    Dim TestArray() As String = my_field.Split(New Char() {" "c})
    Dim word as String      
    For Each word In TestArray
        result = result + word + vbCrLf 
    Next
    Return result

End Function

将函数添加到报表后,您可以从表达式中调用它

=Code.mySplit(Fields!myField.Value)

它将根据单个空格 (" ") 和 return 由新行分隔的值拆分值 vbCrLf

示例:

=Code.mySplit("This is a test")

它returns:

This
is
a
test

更新:函数不会return额外的新行。

Public Function mySplit(ByVal my_field As String) As String
    Dim result As String = ""       
    If my_field is Nothing or my_field = "" Then
        Return result
    End If
    Dim TestArray() As String = my_field.Split(New Char() {" "c})
    Dim word as String
    Dim counter as Integer = 0      
    For Each word In TestArray
        counter = counter +1
        If counter = TestArray.Length Then
            result = result + word
        Else
                result = result + word + vbCrLf 
        End if
    Next
    Return result

End Function

如果这对你有帮助,请告诉我。