SQL 2005 Reporting Services if check for null

前端 未结 5 395
Happy的楠姐
Happy的楠姐 2021-01-19 00:41

In SSRS 2005 I have a table with a dataset linked to it. I want to check if the value of a field is null and if it is not null then format the data to make sure it has one d

相关标签:
5条回答
  • 2021-01-19 01:17

    I would try using ISNULL(fieldname, 0) when querying for your dataset.

    If you are connecting to a datasource without an ISNULL operator (ie. Oracle) then try using COALESCE(fieldname, 0), which iSeries, oracle and sql all support.

    0 讨论(0)
  • 2021-01-19 01:26

    You could check for null in the SQL query instead of at the report level. Like IsNull(fieldname,0) then just format for the %. Provided of course your data is from SQL Server.

    0 讨论(0)
  • 2021-01-19 01:29

    SSRS expressions are evaluated using Visual Basic, which usually does a full (i.e. not a short-circuit) evaluation of all operands in an expression, e.g. in IIf(cond, truexp, falsexp), besides cond, both truexp and falsexp are evaluated and may throw regardless of the value of cond.

    Since there doesn't seem to be a coalescing function in VB.NET 2.0, you might want to add one into the Code section of the report, e.g. for Decimal as returned from Oracle

    Function Coalesce(fieldValue As Object, defaultValue As Decimal) As Decimal
      If IsDBNull(fieldValue) OrElse IsNothing(fieldValue) Then
        Coalesce = defaultValue
      Else
        Coalesce = CDec(fieldValue) 
      End If
    End Function
    

    It would be possible to define a generic function, too, e.g. Coalesce(Of TResult).

    0 讨论(0)
  • 2021-01-19 01:33

    Try using IsDBNull

    0 讨论(0)
  • 2021-01-19 01:42

    When I had this problem I used a switch statement, it evaluates the conditions in the order that it is written, and seems to me to get around both side of the iif statement being evaluated at the same time.

    Ian

    0 讨论(0)
提交回复
热议问题