HOW TO: Use an single quotation mark/apostrophe in a literal string expression

Version 1

    Can an single quotation mark/apostrophe ( ' ) be used in a literal string used in an expression?

     

    Yes. This can be done using the ASCII value (39) for an apostrophe with the CHR function with the concatenation function ( || ) as follows:

    || CHR(39) ||

     

     

    EXAMPLE A:

     

    Source data as follows:

    'don't call'

    Problem: How do you use the IIF function to compare the "don't" string when it contains an apostrophe. The following expression will not work:

    IIF (INPUT_STRING='don't call', RESULT1,RESULT2)

     

    Solution: The following tests where the INPUT_STRING contains the word "don't":

    IIF (INPUT_STRING='don' || CHR(39) || 't', RESULT1,RESULT2)

     

    EXAMPLE B:

     

    The input is:

    Hello World

    The output should be:

    'Hello World'

    Problem: How do you write a string with 'Hello World' using the single quotes as a literal in an expression?

     

    Solution: The following returns the literal phrase 'Hello World':

    CHR(39)||'Hello World'||CHR(39)