Print

SSRS Display question mark when date is blank

Applies to:
What?
So I have a column in an SSRS report which displays a date. Being rather pernickety, I would like a question mark to display if there is no date to populate the field.

Why?
At the moment, the expression in there is something like this:
copyraw
=Format(Fields!MyCompletionTime.Value, "dd/MM/yyyy HH:mm:ss")
-- yields 11/02/2014 11:21:32
  1.  =Format(Fields!MyCompletionTime.Value, "dd/MM/yyyy HH:mm:ss") 
  2.  -- yields 11/02/2014 11:21:32 
Sounds good, where's the problem?

The problem
Putting the date in an IIF (if-then-else) statement displays "#Error". You should get errors referring to converting strings to dates and incorrect data types.

How?
The fix is to simply get the field and both results to be of the same data type:
copyraw
=IIF(CStr(Fields!MyCompletionTime.Value)"", Cstr(Fields!MyCompletionTime.Value), "?")
  1.  =IIF(CStr(Fields!MyCompletionTime.Value)"", Cstr(Fields!MyCompletionTime.Value), "?") 
Category: SQL Server Reporting Services :: Article: 562