2016-01-30 33 views
0

我用下面的文章(ssrs expression to split string possible?),让我从一个SQL列取数据的格式如下:SSRS表达分割字符串

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 

回答

1

我想你可以使用自定义代码来解决问题。

转到Report manu,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) 

称之为它将基于单个空格(”“)拆分值,并返回被新线vbCrLf分隔值。

例子:

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

它返回:

This 
is 
a 
test 

UPDATE:功能将不返回额外的新生产线。

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 

让我知道这是否对您有帮助。

+0

这看起来太棒了,现在就试试吧! – PnP

+0

这似乎给我在拆分上的流氓额外的新行。查看我的编辑 – PnP

+0

@PnP,看起来你的字段中的单词被双空格分隔。检查单词之间的空格 –