【问题标题】:SSRS Expression to Split and Return Every Field in Comma Separated StringSSRS 表达式拆分并返回逗号分隔字符串中的每个字段
【发布时间】:2020-08-06 20:08:49
【问题描述】:

我有一个字符串以ID::Description,ID2::Description2 的格式传递到SSRS。这可以扩展到用逗号分隔的任意数量的字符串。我需要能够:

  1. 拆分字符串只显示Description
  2. 返回所有可能的Descriptions,无论有多少。我知道 SSRS 函数 Split 可以用逗号拆分并返回 .GetValue(<index>),但我需要能够返回所有可能字符串数量不确定的索引。

规定:我不能修改数据库端的数据,这必须通过SSRS内部的表达式来完成。

SSRS 版本:13.0.5820.21

【问题讨论】:

    标签: sql-server reporting-services


    【解决方案1】:

    我可以用一个函数解决这个问题。

    Function FormatDocs(str as String) as String
         Dim rtn as String = ""
         Dim strElements = str.Split(",")
         For i as Integer = 0 to UBound(strElements)
              rtn = rtn + ParseCode(strElements(i), "D")
              If i <> UBound(strElements) Then
                   rtn = rtn + ", "
              End If
         Next
         Return rtn
    End Function
    

    ParseCode 是我们现有的函数,它在 :: 上拆分单个 ID::Description 字符串并返回 Description

    该函数的定义如下:

    Function ParseCode(codeValue As String, returnType As String) As String
        Dim rtn As String = "" 
        If Len(codeValue)  Then
           Dim codeElements = codeValue.Split(":")
           If returnType  = "C"  Then 
             rtn =codeElements(0) 
           Else
             rtn =rtn +  codeElements(2)  
           End If 
        End If
        Return rtn
    End Function 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-21
      • 1970-01-01
      • 2013-11-18
      • 1970-01-01
      • 2015-03-07
      • 1970-01-01
      相关资源
      最近更新 更多