Search code examples
reporting-servicesssrs-2012

How do I get a date in the format of "mmm-YYYY" given a month and a year in SSRS


I have the following expression in my SSRS template:

=UCase(Left(MonthName(Fields!theMonth.Value), 3)) + "-" + Fields!theYear.Value

If I take out this bit:

+ Fields!theYear.Value

The expression works as expected and returns "FEB-" if theMonth is 2.

However SSRS returns an error when I add the year back in.

Any pointers would be appreciated.


Solution

  • Use & NOT + to concatenate strings.

    + works much of the time except when mixing types. Since there's an integer, the expression assumes that you are doing math(s).

    & is used for strings and will convert numbers to strings for the expression.

    The expression

    =UCase(MonthName(5, 1)) + "-" + 2018
    

    throws an error.

    The Value expression for the textrun ‘Textbox1.Paragraphs[0].TextRuns[0]’ contains an error: Input string was not in a correct format.

    But changing just the + to & does not get an error.

    =UCase(MonthName(5, 1)) & "-" & 2018
    

    enter image description here

    On another note:

    MonthName has an optional parameter for abbreviations - just add ,1 after theMonth.Value - UCase(MonthName(Fields!theMonth.Value, 1), 3)