SSRS-字符串的单独部分并返回

时间:2018-10-05 05:25:00

标签: reporting-services expression

我拼命尝试用表达式(Mid / InStr)分隔字符串的特定部分。

字符串:从“ Doe,John”转移到“”,从“客户”组转移到“服务”

我需要组值:服务

有人可以帮忙吗?有可能吗?

1 个答案:

答案 0 :(得分:0)

我能够用一个功能来做到这一点。


示例:

screenshot


文本框表达式:

=Code.GetTransferedGroup(Fields!YourColumnNameHere.Value)


代码:

Public Function GetTransferedGroup(columnValue As String) As String
'--------------------------------------------------------------------------------------------------------------------
' Purpose:      Seperate part of a string
' Example:      =Code.GetTransferedGroup("Transfered from 'Doe, John' to '', Transfered from Group 'Customer' to 'Service'")
' Reference:    https://stackoverflow.com/questions/52658830/ssrs-seperate-part-of-a-string-and-return
'--------------------------------------------------------------------------------------------------------------------
Const transferedHeader   As String = "Transfered from Group"
Const transferedTerm     As String = " to "
Dim transferedPart       As Integer
Dim transferedValues     As String

    Try
        transferedPart = InStr(1, columnValue, transferedHeader, vbBinaryCompare)
        transferedValues = Mid(columnValue, transferedPart + Len(transferedHeader) + 1, Len(columnValue) - (transferedPart + Len(transferedHeader)))
        return Replace(Mid(transferedValues, InStr(1, transferedValues, transferedTerm) + Len(transferedTerm), Len(transferedValues) - InStr(1, transferedValues, transferedTerm)), "'", "")

    Catch 
        return "Error"

    End Try

End Function

报告属性代码:

screenshot