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,那麼它會拋出一個異常並返回一個錯誤。 –