使用 LookupSet 删除重复函数,在 SSRS 中返回#Error
Remove Duplicate Function with LookupSet returing #Error in SSRS
在我的 SSRS
报告中,我将 LOOKUPSET
函数用于 concatenate
field values
之一。为了获得 distinct concatenated
值,我在报告代码中使用了 RemoveDuplicates
Vb 函数。
function
代码是:
Public Shared Function RemoveDuplicates(ByVal items As Object()) As String()
System.Array.Sort(items)
Dim k As Integer = 0
For i As Integer = 0 To items.Length - 1
If i > 0 AndAlso items(i).Equals(items(i - 1)) Then
Continue For
End If
items(k) = items(i)
k += 1
Next
Dim unique As [String]() = New [String](k - 1) {}
System.Array.Copy(items, 0, unique, 0, k)
Return unique
End Function
我的文本框 Expression
是,
=Join(Code.RemoveDuplicates(LookUpSet(Fields!id.Value,
Fields!id.Value,
Fields!code.Value,
"ds_DataSet1")), " , ")
此 expression
在除 blanks
之外的所有情况下都工作正常。如果 Fields!code.Value
仅包含空白,报告预览 Returns 中的错误 #Error
field value
.
当我从 expression
中删除 RemoveDuplicates
函数时,它适用于所有情况。我是否需要在 vb function
中进行更改以合并空格?我在这里缺少什么?
要解决此问题,请对您的代码进行以下更改:
更改函数如下:(null/nothing values will be then converted to empty string '')
Public Shared Function RemoveDuplicates(ByVal items As Object()) As String()
For j As Integer = 0 To items.Length - 1
If j > 0 Then
Continue For
End If
if(items(j) is nothing) then
items(j) = ""
End If
Next
System.Array.Sort(items)
Dim k As Integer = 0
For i As Integer = 0 To items.Length - 1
If i > 0 AndAlso items(i).Equals(items(i - 1)) Then
Continue For
End If
items(k) = items(i)
k += 1
Next
Dim unique As [String]() = New [String](k - 1) {}
System.Array.Copy(items, 0, unique, 0, k)
Return unique
End Function
修改表达式以删除空字符串:
=Replace(
Join(Code.RemoveDuplicates(
LookUpSet(Fields!id.Value, Fields!id.Value, Fields!code.Value,"ds_DataSet1")
), " , ")
, ", ,", "")
要处理空白字段,请更新您的共享函数代码,如下所示:
Public Shared Function RemoveDuplicates(ByVal items As Object()) As String()
System.Array.Sort(items)
Dim k As Integer = 0
For i As Integer = 0 To items.Length - 1
If i > 0 AndAlso items(i) <> "" AndAlso items(i).Equals(items(i - 1)) Then
Continue For
End If
items(k) = items(i)
k += 1
Next
Dim unique As [String]() = New [String](k - 1) {}
System.Array.Copy(items, 0, unique, 0, k)
Return unique
End Function
此外,更新文本框表达式以删除空字符串,如
=IIF(IsNothing(Code.RemoveDuplicates(LookupSet(
Fields!id.Value,
Fields!id.Value,
Fields!code.Value,
"ds_DataSet1"))(0)), "",
Join(Code.RemoveDuplicates(LookUpSet(
Fields!id.Value,
Fields!id.Value,
Fields!code.Value,
"ds_DataSet1")), " , "))
干杯,
基尔蒂·辛格 | IT 服务解决方案
我遇到了类似的问题,后来发现这是由于 LookupSet 的输出与自定义函数不兼容造成的。我在 LookupSet 函数的输出及其两个输入上使用 CStr() 解决了它。
这解决了我的问题。
在我的 SSRS
报告中,我将 LOOKUPSET
函数用于 concatenate
field values
之一。为了获得 distinct concatenated
值,我在报告代码中使用了 RemoveDuplicates
Vb 函数。
function
代码是:
Public Shared Function RemoveDuplicates(ByVal items As Object()) As String()
System.Array.Sort(items)
Dim k As Integer = 0
For i As Integer = 0 To items.Length - 1
If i > 0 AndAlso items(i).Equals(items(i - 1)) Then
Continue For
End If
items(k) = items(i)
k += 1
Next
Dim unique As [String]() = New [String](k - 1) {}
System.Array.Copy(items, 0, unique, 0, k)
Return unique
End Function
我的文本框 Expression
是,
=Join(Code.RemoveDuplicates(LookUpSet(Fields!id.Value,
Fields!id.Value,
Fields!code.Value,
"ds_DataSet1")), " , ")
此 expression
在除 blanks
之外的所有情况下都工作正常。如果 Fields!code.Value
仅包含空白,报告预览 Returns 中的错误 #Error
field value
.
当我从 expression
中删除 RemoveDuplicates
函数时,它适用于所有情况。我是否需要在 vb function
中进行更改以合并空格?我在这里缺少什么?
要解决此问题,请对您的代码进行以下更改:
更改函数如下:(null/nothing values will be then converted to empty string '')
Public Shared Function RemoveDuplicates(ByVal items As Object()) As String()
For j As Integer = 0 To items.Length - 1
If j > 0 Then
Continue For
End If
if(items(j) is nothing) then
items(j) = ""
End If
Next
System.Array.Sort(items)
Dim k As Integer = 0
For i As Integer = 0 To items.Length - 1
If i > 0 AndAlso items(i).Equals(items(i - 1)) Then
Continue For
End If
items(k) = items(i)
k += 1
Next
Dim unique As [String]() = New [String](k - 1) {}
System.Array.Copy(items, 0, unique, 0, k)
Return unique
End Function
修改表达式以删除空字符串:
=Replace(
Join(Code.RemoveDuplicates(
LookUpSet(Fields!id.Value, Fields!id.Value, Fields!code.Value,"ds_DataSet1")
), " , ")
, ", ,", "")
要处理空白字段,请更新您的共享函数代码,如下所示:
Public Shared Function RemoveDuplicates(ByVal items As Object()) As String()
System.Array.Sort(items)
Dim k As Integer = 0
For i As Integer = 0 To items.Length - 1
If i > 0 AndAlso items(i) <> "" AndAlso items(i).Equals(items(i - 1)) Then
Continue For
End If
items(k) = items(i)
k += 1
Next
Dim unique As [String]() = New [String](k - 1) {}
System.Array.Copy(items, 0, unique, 0, k)
Return unique
End Function
此外,更新文本框表达式以删除空字符串,如
=IIF(IsNothing(Code.RemoveDuplicates(LookupSet(
Fields!id.Value,
Fields!id.Value,
Fields!code.Value,
"ds_DataSet1"))(0)), "",
Join(Code.RemoveDuplicates(LookUpSet(
Fields!id.Value,
Fields!id.Value,
Fields!code.Value,
"ds_DataSet1")), " , "))
干杯,
基尔蒂·辛格 | IT 服务解决方案
我遇到了类似的问题,后来发现这是由于 LookupSet 的输出与自定义函数不兼容造成的。我在 LookupSet 函数的输出及其两个输入上使用 CStr() 解决了它。
这解决了我的问题。