<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic escaping script variable strings in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173859#M42890</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, I misunderstood the reference manual and thought you always had to use dollar expansion with scripting variables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 06 Nov 2010 19:49:32 GMT</pubDate>
    <dc:creator />
    <dc:date>2010-11-06T19:49:32Z</dc:date>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173847#M42878</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm loading a script variable, say vS, with a load/peek which I then need to use in a subsequent load/SQL. The example below illustrates the problem using inline/resident rather than SQL data sources, but the issue is the same.&lt;/P&gt;&lt;PRE&gt;some_metadata:LOAD * INLINE [Sh'ello];temp:NOCONCATENATE LOAD SRESIDENT some_metadata;LET vS = PEEK('S', 0, 'temp');DROP TABLE temp;raw_data:LOAD * INLINE [raw_x,raw_y1,goodbye2,h'ello];data:LOAD raw_x as x, raw_y as yRESIDENT 'raw_data'WHERE raw_y = '$(vS)';&lt;/PRE&gt;&lt;P&gt;This works until S contains a single quote. I'm familiar with decomposing a string and then using '&amp;amp;' concatenation and CHR(39) in some contexts, but I'm not sure what to do in this case.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Nov 2010 14:45:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173847#M42878</guid>
      <dc:creator />
      <dc:date>2010-11-05T14:45:24Z</dc:date>
    </item>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173848#M42879</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;try the following in your last WHERE clause&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;WHERE Replace(raw_y, chr(39), chr(39) &amp;amp; chr(39)) = '$(vS)';&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;Hope that helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Nov 2010 18:28:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173848#M42879</guid>
      <dc:creator>Miguel_Angel_Baeyens</dc:creator>
      <dc:date>2010-11-05T18:28:07Z</dc:date>
    </item>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173849#M42880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Miguel,&lt;/P&gt;&lt;P&gt;that was a cool thing to know.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Nov 2010 18:37:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173849#M42880</guid>
      <dc:creator>boorgura</dc:creator>
      <dc:date>2010-11-05T18:37:17Z</dc:date>
    </item>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173850#M42881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, that works!&lt;/P&gt;&lt;P&gt;I assumed my problem was that the expansion of --'$(vS)'-- would be --'h'ello'-- and break the script. Since your suggestion worked, that suggests that QV is taking care of allowing script variables with single quotes to be expanded inside string literals (with single quotes) by doubling up the inner single quotes (which is also the SQL convention, I think). So the expansion becomes --'h''ello'--. Then doubling up the quotes that are literally present in the data evens things up for the comparison.&lt;/P&gt;&lt;P&gt;Can anyone comment on my interpretation of what QV is doing? Obviously thinking QV was doing the very simplest text substitution for the script variable expansion was wrong. It would be great to hear someone describe the complete picture. The documentation I've read doesn't go deep enough for me. For example, do single quotes always turn into pairs of single quotes during expansion, or only if the expansion is inside single quotes? Are there any other things to know about expansion?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Nov 2010 19:05:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173850#M42881</guid>
      <dc:creator />
      <dc:date>2010-11-05T19:05:57Z</dc:date>
    </item>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173851#M42882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In similar cases, I simply remove single quote from the string completely:&lt;BR /&gt;LET vS = purgechar(peek(...), chr(39))&lt;BR /&gt;WHERE purgechar(ray_y, chr(39)) = ...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Nov 2010 19:06:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173851#M42882</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-11-05T19:06:02Z</dc:date>
    </item>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173852#M42883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You're right, QlikView script replaces&lt;BR /&gt;WHERE raw_y = '$(vS)'&lt;BR /&gt;with&lt;BR /&gt;WHERE raw_y = 'h'&lt;STRONG&gt;ello'&lt;/STRONG&gt;&lt;BR /&gt;You can see this in the log file.&lt;/P&gt;&lt;P&gt;Now, the problem here is that the correct syntax&lt;BR /&gt;WHERE raw_y = 'h'&lt;BR /&gt;is followed by &lt;STRONG&gt;ello&lt;/STRONG&gt;, which it doesn't understand at all. And, the last quota is interpreted as the opening of a string that maybe never ends - the script is broken.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Nov 2010 19:25:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173852#M42883</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-11-05T19:25:47Z</dc:date>
    </item>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173853#M42884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your input. I'm confused. I tested what Miguel posted, and it works. How can what you're saying also be true? In my last post, I was saying that I had falsely assumed what you are describing would happen.&lt;/P&gt;&lt;P&gt;Do you have a test case which illustrates what you are stating in your post? I just tested it again. I trust you're seeing that in the log, but maybe the log isn't presenting things accurately. I added more side effects to observe what happens after the statement in question when the script variable contains a single quote. The never-closing single quote problem is not happening in my test.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Nov 2010 19:49:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173853#M42884</guid>
      <dc:creator />
      <dc:date>2010-11-05T19:49:07Z</dc:date>
    </item>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173854#M42885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't see any contradiction between Miguel's solution and my statement. I'm certain that it works, only suggesting an alternative which I prefer. There are often many ways to achieve the same result.&lt;BR /&gt;As for the log - turrn the logging on, and see what will be created. I've never had a situation where log misrepresents actual script execution.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Nov 2010 19:56:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173854#M42885</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-11-05T19:56:56Z</dc:date>
    </item>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173855#M42886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Agreed; there are many ways to achieve the same result. I like the purgechar() approach too.&lt;/P&gt;&lt;P&gt;The contradiction involves your 11-05-2010 2:25 PM post. Miguel's solution works. It leaves the --'$(vS)'-- in the script. The value of S in the data table is --h'ello--, so by your statement, the script is broken when --'$(vS)'-- expands if vS contains a single quote. But it's not broken, and/or I'm making mistakes in my testing. Here's my new test case. Can you explain why it does work?&lt;/P&gt;&lt;PRE&gt;some_metadata:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;S&lt;BR /&gt;h'ello&lt;BR /&gt;];&lt;BR /&gt;&lt;BR /&gt;temp:&lt;BR /&gt;NOCONCATENATE LOAD S&lt;BR /&gt;RESIDENT some_metadata;&lt;BR /&gt;LET vS = PEEK('S', 0, 'temp');&lt;BR /&gt;DROP TABLE temp;&lt;BR /&gt;&lt;BR /&gt;raw_data:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;raw_x,raw_y&lt;BR /&gt;h'ello,goodbye&lt;BR /&gt;2,h'ello&lt;BR /&gt;];&lt;BR /&gt;&lt;BR /&gt;data:&lt;BR /&gt;LOAD&lt;BR /&gt; raw_x as x, raw_y as y&lt;BR /&gt;RESIDENT 'raw_data'&lt;BR /&gt;WHERE&lt;BR /&gt; Replace(raw_y, chr(39), chr(39) &amp;amp; chr(39)) = '$(vS)' OR&lt;BR /&gt; Replace(raw_x, chr(39), chr(39) &amp;amp; chr(39)) = '$(vS)';&lt;BR /&gt;&lt;BR /&gt;vTest=999;&lt;BR /&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Nov 2010 20:26:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173855#M42886</guid>
      <dc:creator />
      <dc:date>2010-11-05T20:26:45Z</dc:date>
    </item>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173856#M42887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, I just tried. Have to tell, that to my surpise, the line&lt;BR /&gt;WHERE raw_y = '$(vS)'&lt;BR /&gt;was translated to 'h''ello' - two quotes between h and ello, although the value of the variable is "h'ello", with only one quote. So, there is no never-closing quote, there are two - 'h', and 'ello'. Something to think about...&lt;BR /&gt;I also tried the purgechar() - worked as expected.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Nov 2010 01:27:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173856#M42887</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-11-06T01:27:28Z</dc:date>
    </item>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173857#M42888</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for verifying what's happening.&lt;/P&gt;&lt;P&gt;The two ways I've seen for escaping the enclosing characters (single quote in this case) in a language token are: 1) have a different escape character (backslash is common; then to express a backslash you would double the backslash) or 2) double the enclosing character if it appears within the token. QV apparently uses the later method which is just like SQL string constants.&lt;/P&gt;&lt;P&gt;It would be nice to have this information documented in the reference manual.&lt;/P&gt;&lt;P&gt;Everything learned so far applies to the load script. But this isn't the end of my problems. Now try to take the --$(vS)-- and show it in a text box while it contains a single quote. None of the following works:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;$(vS)&lt;/LI&gt;&lt;LI&gt;$(=vS)&lt;/LI&gt;&lt;LI&gt;=$(vS)&lt;/LI&gt;&lt;LI&gt;=$(=vS)&lt;/LI&gt;&lt;LI&gt;'$(vS)'&lt;/LI&gt;&lt;LI&gt;'$(=vS)'&lt;/LI&gt;&lt;LI&gt;='$(vS)'&lt;/LI&gt;&lt;LI&gt;='$(=vS)'&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Nov 2010 03:28:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173857#M42888</guid>
      <dc:creator />
      <dc:date>2010-11-06T03:28:47Z</dc:date>
    </item>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173858#M42889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It will be&lt;BR /&gt;=vS&lt;/P&gt;&lt;P&gt;See attached&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Nov 2010 14:17:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173858#M42889</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-11-06T14:17:12Z</dc:date>
    </item>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173859#M42890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, I misunderstood the reference manual and thought you always had to use dollar expansion with scripting variables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Nov 2010 19:49:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173859#M42890</guid>
      <dc:creator />
      <dc:date>2010-11-06T19:49:32Z</dc:date>
    </item>
    <item>
      <title>escaping script variable strings</title>
      <link>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173860#M42891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sometimes $() is not necessary, usualy on the front end. And, if not for the apostrophe, your last two versions would be working as well.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Nov 2010 14:25:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/escaping-script-variable-strings/m-p/173860#M42891</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-11-07T14:25:07Z</dc:date>
    </item>
  </channel>
</rss>

