在 SSRS 中使用 Split、Join 和其他功能

Use Split, Join, and another function in SSRS

我在 SQL 服务器中有一个包含逗号分隔列表的字段。这里有 2 个例子:

select 'ex1,ex2,ex3' as str union all
select 'ax1,ax2' 

在我的报告中,我必须使用函数转换所有这些值(在本例中为 5)。在这个问题中,我将使用 Trim,但实际上我们使用的是另一个具有相同作用域的自定义函数。

我知道如何拆分字符串中的每个值并重新组合它们:

=Join(Split(Fields!str.Value,","),", ")

效果很好。但是,我需要在重新组合这些值之前执行一个函数。我认为这会起作用:

=Join( Trim(Split(Fields!VRN.Value,",")) ,", ")

然而,这只是给我一个错误:

Value of type '1-dimensional array of String' cannot be converted to 'String'. (rsCompilerErrorInExpression)

我不能亲自更改我们使用的功能。

如何在处理拆分和连接时使用额外的函数?

您可以使用自定义代码来包含所有逻辑(拆分->自定义代码->合并)。

在循环内进行调整以调用您的自定义函数而不是 trim

Public Function fixString (ByVal s As String) As String

Dim  mystring() As String  

mystring = s.Split(",")

For index As Integer = 0 To mystring.Length-1
    mystring(index) = Trim(mystring(index))
Next 

Return Join(mystring, ",")

End Function

要调用自定义代码,请使用以下表达式

Code.fixString( Fields!VRN.Value )