SSRS 自定义函数和 Null 值
SSRS Custom function and Null values
我正在尝试使用自定义函数来确定指标的值。问题是传递给函数的字段可以为 NULL。我使参数的类型可以为空,但它不会让我进行任何比较。我不知道为什么。
错误是"There is an error on line 20 of custom code: [BC30452] Operator '<' is not defined for types 'System.Nullable(Of Single)' and 'System.Nullable(Of Single)'."
Public Function GetIndicator(ByVal HistBal As Nullable(of single),ByVal CurBal as NULLABLE(of single)) as integer
Dim iReturn as integer
if NOT HistBal.HasValue Then
iReturn =0
else If HistBal< CurBal then
If (HistBal-CurBal)/HistBal <-.1 Then
iReturn= 2 'Green arrow
Else
iReturn= 4 'Up yellow
end if
Else if HistBal=CurBal then
iReturn=0 'blank
else
If (HistBal-CurBal)/HistBal <.1 Then
iReturn= 3 'Dn yellow
Else
iReturn= 1 'red arrow
end if
End if
return iReturn
End Function
更新:
代码 returns #ERROR:
Public Function GetIndicator(ByVal HistBal As Nullable(of single),ByVal CurBal as NULLABLE(of single)) as integer
Dim iReturn as integer
if Not HistBal.HasValue or Not CurBal.HasValue Then
iReturn =0
else
iReturn= 1
End if
return iReturn
End Function
Operator '<' is not defined for types 'System.Nullable(Of Single)' and 'System.Nullable(Of Single)'.
正如消息所说:显然 System.Nullable(Of T)
没有定义 <
运算符。
您已经在检查是否 HistBal.HasValue
。只需检查 CurBal.HasValue
并实现逻辑,当其中一个或两个值为 null
时确定 return 的内容,然后在分支中处理 HistBal.Value
和 CurBal.Value
已知两者都具有非空值。
If Not HistBal.HasValue Or Not CurBal.HasValue Then
Return 0 'presumably return 0 when either value is null
End If
If HistBal.Value < CurBal.Value Then 'work off the Single, not the nullable
'...
我正在尝试使用自定义函数来确定指标的值。问题是传递给函数的字段可以为 NULL。我使参数的类型可以为空,但它不会让我进行任何比较。我不知道为什么。
错误是"There is an error on line 20 of custom code: [BC30452] Operator '<' is not defined for types 'System.Nullable(Of Single)' and 'System.Nullable(Of Single)'."
Public Function GetIndicator(ByVal HistBal As Nullable(of single),ByVal CurBal as NULLABLE(of single)) as integer
Dim iReturn as integer
if NOT HistBal.HasValue Then
iReturn =0
else If HistBal< CurBal then
If (HistBal-CurBal)/HistBal <-.1 Then
iReturn= 2 'Green arrow
Else
iReturn= 4 'Up yellow
end if
Else if HistBal=CurBal then
iReturn=0 'blank
else
If (HistBal-CurBal)/HistBal <.1 Then
iReturn= 3 'Dn yellow
Else
iReturn= 1 'red arrow
end if
End if
return iReturn
End Function
更新:
代码 returns #ERROR:
Public Function GetIndicator(ByVal HistBal As Nullable(of single),ByVal CurBal as NULLABLE(of single)) as integer
Dim iReturn as integer
if Not HistBal.HasValue or Not CurBal.HasValue Then
iReturn =0
else
iReturn= 1
End if
return iReturn
End Function
Operator '<' is not defined for types 'System.Nullable(Of Single)' and 'System.Nullable(Of Single)'.
正如消息所说:显然 System.Nullable(Of T)
没有定义 <
运算符。
您已经在检查是否 HistBal.HasValue
。只需检查 CurBal.HasValue
并实现逻辑,当其中一个或两个值为 null
时确定 return 的内容,然后在分支中处理 HistBal.Value
和 CurBal.Value
已知两者都具有非空值。
If Not HistBal.HasValue Or Not CurBal.HasValue Then
Return 0 'presumably return 0 when either value is null
End If
If HistBal.Value < CurBal.Value Then 'work off the Single, not the nullable
'...