1
我正在尝试使用自定义函数来确定指标的值。问题是传递给函数的字段可以是NULL。我使参数的类型为空,但不会让我做任何比较。我不知道为什么。SSRS自定义函数和空值
错误是“自定义代码的第20行存在错误:[BC30452]运算符'<'未针对类型'System.Nullable(Of Single)'和'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
UPDATE:返回#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
谢谢。以前从未使用过这个Nullable参数。 – user1612851
它编译,但我从该函数返回#Error。这个函数在我把它设为可空参数之前就工作了。 – user1612851
进展!这个'#Error'是一个不同的问题,涉及不同的代码。我不知道你做了什么或者你给了什么输入。你的代码目前没有检查'CurBal.HasValue',如果它是null,那么它会抛出一个异常并返回一个错误。 –