【问题标题】:Checking for NULL dates in custom code function在自定义代码函数中检查 NULL 日期
【发布时间】:2012-02-07 22:09:27
【问题描述】:

我正在尝试为我的 SSRS 报告实现一个函数,该函数将根据三个日期的值返回一个颜色值:

Function SetBoxColor(dateOne As Date, dateTwo As Date, dateThree As Date) As String
' Determine colors for text box
  If (dateOne Is Nothing) Then
    SetBoxColor = "Blue"
  Else
    If (dateThree Is Nothing) Then
      If dateOne >= Date.Now Then
        If DateDiff("d",dateOne,Date.Now) < 90
          SetBoxColor = "Yellow"
        Else
          SetBoxColor = "White"
        End If
      Else
        SetBoxColor = "Orange"
      End If
    Else
      If dateThree <= dateOne Or (Month(dateThree) = Month(dateOne) And Year(dateThree) = Year(dateOne)) Then
        SetBoxColor = "Green"
      Else
        SetBoxColor = "Red"
      End If
    End If
  End If
  Return SetBoxColor
End Function

传递给此函数的参数是来自我的数据集的可空日期(SQL Server 日期类型),我从 TextBox 的 BackgroundColor 属性调用该函数:

=Code.SetBoxColor(Fields!dateOne.Value, Fields!dateTwo.Value, Fields!dateThree.Value)

按原样运行函数会返回错误:

“Is”需要具有引用类型的操作数,但该操作数的值类型为“Date”。

任何帮助将不胜感激。

【问题讨论】:

    标签: vb.net reporting-services sql-server-2008-r2


    【解决方案1】:

    你试过dateOne = Nothing吗?

    【讨论】:

    • 那行得通。我习惯了 SQL Server 无法使用 = 评估 NULL,只是假设 'is' 是我需要的。
    猜你喜欢
    • 1970-01-01
    • 2016-07-14
    • 2018-01-17
    • 2023-03-08
    • 1970-01-01
    • 2012-01-19
    • 2021-09-07
    • 2018-12-08
    • 1970-01-01
    相关资源
    最近更新 更多