none
Is there an escape character in SSRS scripting?

    Question

  • Hi,

    I'm using SQL 2005. I need to include a double quote (") within a string in a report textbox. How do I do this? I've tried to escape it with a backslash, tried using ", etc.

    Thanks in advance!
    Web: http://invoc.net Blog: http://invoc.net/CRM_BPOS_Blog
    Tuesday, February 02, 2010 6:20 PM

Answers

  • Hi Andy,

    Char(34) needs to be outside of the double quotes:

    ="Hi, my name is " & Chr(34) & "ANDY" & Chr(34) & " Schultz and I am " + Fields!age.Value.ToString()


    Please let me know if you come across a cleaner way to do this  :-)

    Hope this helps!


    Cheers,
    Lawrence
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, February 02, 2010 7:27 PM
    Answerer
  • Andy,

    You almost got it.  Your expression should be this:

    ="Hi, my name is " & Chr(34) & "ANDY" & Chr(34) & " Schultz and I am " & Fields!age.Value.ToString()
    Tuesday, February 02, 2010 7:27 PM
  • Expressions in Reporting Services are written using Visual Basic.  To escape double quotes, type it in twice.

    ="Hi, my name is ""ANDY"" Schultz and I am " + Fields!age.Value.ToString()
    Tuesday, February 02, 2010 9:59 PM
    Answerer

All replies

  • Hi Andy,

    One way to do insert double quote is to use the good old ASCII conversion:

    =Chr(34)  & "Hello world" & Chr(34)


    Hope this helps!


    Cheers,
    Lawrence
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, February 02, 2010 7:07 PM
    Answerer
  • Thanks Lawrence, Sounds like it's close -

    When I replace the double quotes with Chr(34), it just shows up literally as "Chr(34)" in my string though. Am I doing it wrong? This is similar to what I need:

    ="Hi, my name is "ANDY" Schultz and I am " + Fields!age.Value.ToString()

    I've replaced that with this:

    ="Hi, my name is Chr(34)ANDYChr(34) Schultz and I am " + Fields!age.Value.ToString()

    Resulting in:

    Hi, my name is Chr(34)ANDYChr(34) Schultz and I am 99.

    Thanks Lawrence!
    Web: http://invoc.net Blog: http://invoc.net/CRM_BPOS_Blog
    Tuesday, February 02, 2010 7:23 PM
  • Andy,

    You almost got it.  Your expression should be this:

    ="Hi, my name is " & Chr(34) & "ANDY" & Chr(34) & " Schultz and I am " & Fields!age.Value.ToString()
    Tuesday, February 02, 2010 7:27 PM
  • Hi Andy,

    Char(34) needs to be outside of the double quotes:

    ="Hi, my name is " & Chr(34) & "ANDY" & Chr(34) & " Schultz and I am " + Fields!age.Value.ToString()


    Please let me know if you come across a cleaner way to do this  :-)

    Hope this helps!


    Cheers,
    Lawrence
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, February 02, 2010 7:27 PM
    Answerer
  • Thank you Lawrence and Aaron! I can't believe I've never had to do that before, but I drew a blank when I ran into the problem.

    Thanks,
    Web: http://invoc.net Blog: http://invoc.net/CRM_BPOS_Blog
    Tuesday, February 02, 2010 9:50 PM
  • Expressions in Reporting Services are written using Visual Basic.  To escape double quotes, type it in twice.

    ="Hi, my name is ""ANDY"" Schultz and I am " + Fields!age.Value.ToString()
    Tuesday, February 02, 2010 9:59 PM
    Answerer
  • Hi... I am having a similar problem with SSRS expression escapes.

    I am using a map, and have an Action to go to a report "by country" on click of the map. When a user clicks on a country where there are no values, I want to direct the user to the country "#NA". Easy until here, but it seems I can not escape the hash (#), it always get it replace by the string "PoligonLayer1_" . I already tried escaping through:

    - Chr(35) : also gets converted to "poligonlay..."

    - "##", "\#", "/#", "&#", "[#]", "#[#]#"

    None of them have worked out. Any suggestions on a Friday afternoon? ;-)

    Thanks!


    • Edited by Lutz Jerschabek Friday, July 26, 2013 2:53 PM added more escape options
    Friday, July 26, 2013 2:51 PM