Error in table on null values

  • I have a table with a field that has to be displayed as a short date format  I'm using

    =Fields!completedDate.Value.toShortDateString

    The problem is that null is a valid value for the field, which of course causes an error for the date function.  Is there any way to use an if statement in the expression to display a blank if the field value is null?

    What I'm looking for is something similar to excel's if(expression, trueval, falseval) construct if such a thing exists.

  • Try the following!!!

    =IIF(Fields!Margin.Value IS Nothing,"",Fields!completedDate.Value.toShortDateString)

    Hope this helps!

     

  • Thanks for the reply!  It put me on the right track for solving it -- though I ended up using the iif on the format rather than the expression itself.

    =IIF (Fields!completedDate.Value IS Nothing, "White", "Black")

     

    The other wouldn't work since it evaluates both the true and false expressions no matter what and still gave an error.  I even tried nesting iif's and had no luck -- the formatting solved the issue though.

  • To handle displaying the null value, you would need to write a function in the report code to handle it, and then use the function to provide the value for the field to display. Something like:

    Public Function DisplayGuid(value As Guid) As String

     If Guid.Equals(value,Guid.Empty) Then

      Return ""

     Else

      Return value.ToString()

     End If

    End Function

    Which I had to use to show GUID values where some of them might be null...GUIDs present their own display problems, too.

  • Martha

    All you need to use is

    =Fields!completedDate.Value

    and then set the Format property of that cell to

    d

    which corresponds to Short date. For more info, search Reporting Services BOL for "Formatting Text".

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply