Domanda

I have a table which has a TEST column which contains many values:

TEST

2014-04-02
2014-04-03
2014-04-04
WEEKLY TOTAL
PRIOR WEEK
12 WEEK

How can I write an expression using IIF statement so if the row contains a date then change the date to a different format?

For example:

The first row has 2014-04-02 (yyyy-mm-dd) which should be changed to 02-Apr (dd-mmm) The last row has 12 week which should not be touched because it's not a date

È stato utile?

Soluzione

Solution 1:

=iif(isDate(Fields!Test.Value)
     ,FORMAT(
            CDATE(iif(isDate(Fields!Test.Value), Fields!Test.Value, Nothing))
           , "dd-MMM"
           ) 
   ,Fields!Test.Value)

Solution 2:
Handle it in SQL itself using CASE WHEN

Altri suggerimenti

IF all of your dates have a '-' AND none of your text has a '-':

=IIF(Fields!TEST.Value like "*-*", FORMAT(CDATE(Fields!TEST.Value), "dd-MMM")  ,Fields!TEST.value)

Not tested, but should work. Edited to return an actual date.

Edit: after some more experimentation, it dawned on me that what you want would result in the SSRS column having an inconsistent type (date/string), and I don't think it is possible to have both string types and date types in the same column.

My mistake was not to realize this sooner.

In order to return actual dates, you will need to clean/filter your data.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top