Search code examples
sql-serverreporting-servicesssrs-expression

difference between + and & in ssrs expression


I am working on SSRS Report.

I have one question, what is the difference between + and & in ssrs-expression?

Please share your answer with short example. Thanks.


Solution

  • Actually its depends on how you are going to use them.

    1.) For Concatenation purpose

    According to MSDN:

    enter image description here

    • using & and + for concatenation will result to the same behaviour or output. It will only concatenates two strings.

    Example:

    = 1 & 2
    

    Output: 12

    = "1" + "2"
    

    Output: 12

    2.) For Arithmetic purpose

    According to MSDN: enter image description here

    • using + for arithmetic purpose will add the two numbers together

    Example:

    = 1 + 2 //(using two numbers)
    

    Output: 3

    = 1 + "2" //(using a number and a number with quotes)
    

    Output: 3
    ------------------------------------------------------------------------
    Exceptions

    Now there are exceptions that an integer and a string is mixed up or with other types

    Example:

    = 1 + "two"
    

    Output: #Error -> this is because they are incompatible with each other.

    • Workaround - use a conversion functions to convert the default data type for a field to the data type needed for calculations or to combine text.

    Example:

    = CSTR(1) + "two"
    

    Output: 1two

    There are other more conversion functions which you can use depending on your needs.