Search code examples
stringreporting-servicessplit

Return value in string based on another value in SSRS


I have a application that uses text templates to ask questions and record answers from end users. The data is stored in a postgres database using HTML. The answers are radio buttons for yes, no, or decline. The HTML string uses a X to mark what answer they chose. An example of the html output is below.

Yes X No Decline

There is a space after the X. I want to return the value after the space.

In this example the answer is No. Other answers may be Yes or Decline depending on where the X is.

How do I evaluate for X and return the Value that follows it (Yes, No or Decline) in a SSRS expression

I've tried doing this in the sql with split_part and regex but am not having luck so I want to try the SSRS side to return the proper value. I've seen examples of instr and mid but I can't seem to get it to work.

Any help appreciated.


Solution

  • You could use Instr to identify the X for the answer.

    Then use the Mid function to grab the part after the X (2 characters including the space after the X, hence the +2).

    Rather than waste time figuring out how many characters the answer is or where the next space is, you can just get 3 characters and TRIM the trailing space from the NO answer.

    =TRIM(Mid(Fields!ANSWER.Value, InStr(Fields!ANSWER.Value, "X") + 2, 3))