<?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 Re: replace and in string in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/replace-and-in-string/m-p/1735853#M56229</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Now this seems a query parsing problem.&lt;/P&gt;&lt;P&gt;Query engines does parse during execution, if you have access such data it would be a nicer solution.&lt;/P&gt;&lt;P&gt;As far as I understand your need, I prepared a replacement procedure without using regex.&lt;/P&gt;&lt;P&gt;I hope this is what you need for:&lt;/P&gt;&lt;P&gt;sub replaceStatement(tablename,seperator,sepReplacement)&lt;/P&gt;&lt;P&gt;$(tablename)_New:&lt;BR /&gt;NoConcatenate&lt;BR /&gt;// unites part with new seperator&lt;BR /&gt;LOAD sqlstatement,concat(part,'$(sepReplacement)',recno) as filter GROUP BY sqlstatement;&lt;BR /&gt;// enumerates lines of part for next step&lt;BR /&gt;LOAD sqlstatement,part,recNo() as recno where mod(substringcount(part,chr(39)),2)=0;&lt;BR /&gt;// if seperator is in a string, unites lines of part until there is no string split wrongly&lt;BR /&gt;LOAD sqlstatement,if(quoteCount=0,part,if(previous(quoteCount)=0,part,previous(part) &amp;amp; '$(seperator)' &amp;amp; part)) as part;&lt;BR /&gt;// checks whether seperator is in a string, or not&lt;BR /&gt;LOAD sqlstatement,part,mod(substringcount(part,chr(39)),2) as quoteCount;&lt;BR /&gt;// forms parts disregarding the seperator&lt;BR /&gt;LOAD sqlstatement,mid(sqlstatement, start, count) as part, start, count;&lt;BR /&gt;// disregards seperator string in parts&lt;BR /&gt;LOAD sqlstatement,if(newstatement=1,start,start+len('$(seperator)')) as start, if(newstatement=1,count,count-len('$(seperator)')) as count;&lt;BR /&gt;// determines start of each part in sqlstatement and characters to count in sqlstatement till the start of next part&lt;BR /&gt;LOAD sqlstatement,if(isnull(previous(start)) or newstatement=1,1,previous(start)) as start, if(start=0,len(sqlstatement)+1,start)-if(isnull(previous(start)),1,previous(start)) as count,newstatement;&lt;BR /&gt;// splits sqlstatement into lines by using seperator variable&lt;BR /&gt;LOAD sqlstatement,if(previous(sqlstatement)&amp;lt;&amp;gt;sqlstatement,1,0) as newstatement,Index(sqlstatement,'$(seperator)', IterNo()) as start while IterNo() &amp;lt;= substringCount(sqlstatement,'$(seperator)')+1;&lt;BR /&gt;LOAD * Resident $(tablename);&lt;/P&gt;&lt;P&gt;drop field sqlstatement from $(tablename)_New;&lt;BR /&gt;drop table $(tablename);&lt;BR /&gt;rename table $(tablename)_New to $(tablename);&lt;BR /&gt;rename field filter to sqlstatement;&lt;/P&gt;&lt;P&gt;end sub&lt;/P&gt;&lt;P&gt;Input:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;sqlstatement&lt;BR /&gt;"record_number = 10 and currency = 'USD' and date=2020-09-30"&lt;BR /&gt;"record_number = 5 and currency = 'USD' and date=2020-5-11"&lt;BR /&gt;"date = '$date' and record_number = 4 and code = 'abc' and segment = 'SUB' and product='pr1 and pr2'"&lt;BR /&gt;"date =date=2121-09-30 and record_number = 5 or code = 'abc' and segment in ('IWM','SRU','SUB','GM and AP','Cor_Centr')"&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;call replaceStatement('Input',' and ',' &amp;amp; ');&lt;BR /&gt;call replaceStatement('Input',' or ', ' || ');&lt;/P&gt;</description>
    <pubDate>Fri, 14 Aug 2020 07:01:08 GMT</pubDate>
    <dc:creator>SerhanKaraer</dc:creator>
    <dc:date>2020-08-14T07:01:08Z</dc:date>
    <item>
      <title>replace and in string</title>
      <link>https://community.qlik.com/t5/App-Development/replace-and-in-string/m-p/1735435#M56183</link>
      <description>&lt;P&gt;I have below string&amp;nbsp;&lt;/P&gt;&lt;P&gt;field1='abc' and field2=3 and field3 in('abc','abc and cde') and field4='a and b'&lt;/P&gt;&lt;P&gt;and I need to convert this as below&amp;nbsp;&lt;/P&gt;&lt;P&gt;field1='abc' &amp;amp; field2=3 &amp;amp;field3 in('abc','abc and cde') &amp;amp; field4='a and b'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 02:52:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/replace-and-in-string/m-p/1735435#M56183</guid>
      <dc:creator>G2</dc:creator>
      <dc:date>2020-08-13T02:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: replace and in string</title>
      <link>https://community.qlik.com/t5/App-Development/replace-and-in-string/m-p/1735450#M56186</link>
      <description>&lt;P&gt;Hello G2,&lt;/P&gt;&lt;P&gt;Does this replacement solve your problem?&lt;/P&gt;&lt;P&gt;replace('field1=''abc'' and field2=3 and field3 in(''abc'',''abc and cde'') and field4=''a and b''','and field','&amp;amp; field')&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 05:43:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/replace-and-in-string/m-p/1735450#M56186</guid>
      <dc:creator>SerhanKaraer</dc:creator>
      <dc:date>2020-08-13T05:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: replace and in string</title>
      <link>https://community.qlik.com/t5/App-Development/replace-and-in-string/m-p/1735505#M56193</link>
      <description>&lt;P&gt;I presume it is not always exactly that string that you need to replace? If so you would just do a replace of the whole lot with the whole replacement.&lt;/P&gt;&lt;P&gt;Is it that you would like to replace the word and with ampersand, as long as the and does not fall within single quotes, for any given string?&lt;/P&gt;&lt;P&gt;What is the context for this requirement, as it may make a big difference to how it is tackled.&lt;/P&gt;&lt;P&gt;It's not straightforward (as you probably already know) and may require a string walk (i.e. read each character at a time and decide what to do), but this will be massively processor hungry if you are doing it over multiple rows.&lt;/P&gt;&lt;P&gt;My best guess at the moment is something like:&lt;/P&gt;&lt;P&gt;replace(replace(replace(replace(replace(replace(&lt;BR /&gt;replace(replace(replace(replace(replace(replace(&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;chr(39) &amp;amp; ' and', chr(39) &amp;amp; ' &amp;amp;'),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;') and', ') &amp;amp;'),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;'1 and', '1 &amp;amp;'),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;'2 and', '2 &amp;amp;'),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;'3 and', '3 &amp;amp;'),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;'4 and', '4 &amp;amp;'),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;'5 and', '5 &amp;amp;'),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;'6 and', '6 &amp;amp;'),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;'7 and', '7 &amp;amp;'),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;'8 and', '8 &amp;amp;'),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;'9 and', '9 &amp;amp;'),&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;'0 and', '0 &amp;amp;')&lt;/P&gt;&lt;P&gt;That is assuming that the word and will only ever come after a bracket, quote or number outside of quotes, and only ever after an alpha inside of quotes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 08:47:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/replace-and-in-string/m-p/1735505#M56193</guid>
      <dc:creator>stevedark</dc:creator>
      <dc:date>2020-08-13T08:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: replace and in string</title>
      <link>https://community.qlik.com/t5/App-Development/replace-and-in-string/m-p/1735577#M56197</link>
      <description>&lt;P&gt;Thanks to Both of you for your reply.&lt;/P&gt;&lt;P&gt;But let me put my requirement in more detail. I have a field where I have sql statement and I want to derive new field as mentioned in requirement using where clause of sql statement.&lt;/P&gt;&lt;P&gt;Basically I have 'and' keyword as concatenation operator between two fields in where clause and also have 'and' as value. and as per my requirement I want to 'and' which is as concatenation operator as &amp;amp; and and as value of field should remain as and only.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please check the bold portion in below table and should return as and and rest of the and should convert as '&amp;amp;'&lt;/P&gt;&lt;TABLE width="1133px"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="80px"&gt;Sr.No&lt;/TD&gt;&lt;TD width="504px"&gt;Source SQL&lt;/TD&gt;&lt;TD width="548px"&gt;requirement&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="80px"&gt;1&lt;/TD&gt;&lt;TD width="504px"&gt;select sum(amount)&lt;BR /&gt;from Table2 where record_number = 4 and currency = 'USD' and date=2020-09-30&lt;/TD&gt;&lt;TD width="548px"&gt;record_number=4&amp;amp;currency=USD&amp;amp;date=2020-09-30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="80px"&gt;2&lt;/TD&gt;&lt;TD width="504px"&gt;select sum(amount)&lt;BR /&gt;from Table2 where record_number = 10 and currency = 'USD' and date=2020-09-30&lt;/TD&gt;&lt;TD width="548px"&gt;record_number=10&amp;amp;currency=USD&amp;amp;date=2020-09-30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="80px"&gt;4&lt;/TD&gt;&lt;TD width="504px"&gt;select sum(amount)&lt;BR /&gt;from Table1 where record_number = 5 and currency = 'USD' and date=2020-5-11&lt;/TD&gt;&lt;TD width="548px"&gt;record_number=5&amp;amp;currency=USD&amp;amp;date=2020-5-11&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="80px"&gt;5&lt;/TD&gt;&lt;TD width="504px"&gt;select sum(amount) from Table3 where date = '$date' and record_number = 4 and code = 'abc' and segment = 'SUB' and product=&lt;EM&gt;&lt;U&gt;&lt;STRONG&gt;'pr1 and pr2'&lt;/STRONG&gt;&lt;/U&gt;&lt;/EM&gt;&lt;/TD&gt;&lt;TD width="548px"&gt;date=2121-09-30&amp;amp;record_number=4&amp;amp;code=abc&amp;amp;segment=SUB&amp;amp;product=&lt;EM&gt;&lt;U&gt;&lt;STRONG&gt;pr1 and pr2&lt;/STRONG&gt;&lt;/U&gt;&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="80px"&gt;6&lt;/TD&gt;&lt;TD width="504px"&gt;select sum(amount) from Table3 where date =date=2121-09-30 and record_number = 5 and code = 'abc' and segment in ('IWM','SRU','SUB',&lt;EM&gt;&lt;U&gt;&lt;STRONG&gt;'GM and AP'&lt;/STRONG&gt;&lt;/U&gt;&lt;/EM&gt;,'Cor_Centr')&lt;/TD&gt;&lt;TD width="548px"&gt;date=2121-09-30&amp;amp;record_number=5&amp;amp;code=abc&amp;amp;segment=IWM,SRU,SUB,&lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;GM and AP&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt;,Cor_Cntr&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 12:48:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/replace-and-in-string/m-p/1735577#M56197</guid>
      <dc:creator>G2</dc:creator>
      <dc:date>2020-08-13T12:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: replace and in string</title>
      <link>https://community.qlik.com/t5/App-Development/replace-and-in-string/m-p/1735853#M56229</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Now this seems a query parsing problem.&lt;/P&gt;&lt;P&gt;Query engines does parse during execution, if you have access such data it would be a nicer solution.&lt;/P&gt;&lt;P&gt;As far as I understand your need, I prepared a replacement procedure without using regex.&lt;/P&gt;&lt;P&gt;I hope this is what you need for:&lt;/P&gt;&lt;P&gt;sub replaceStatement(tablename,seperator,sepReplacement)&lt;/P&gt;&lt;P&gt;$(tablename)_New:&lt;BR /&gt;NoConcatenate&lt;BR /&gt;// unites part with new seperator&lt;BR /&gt;LOAD sqlstatement,concat(part,'$(sepReplacement)',recno) as filter GROUP BY sqlstatement;&lt;BR /&gt;// enumerates lines of part for next step&lt;BR /&gt;LOAD sqlstatement,part,recNo() as recno where mod(substringcount(part,chr(39)),2)=0;&lt;BR /&gt;// if seperator is in a string, unites lines of part until there is no string split wrongly&lt;BR /&gt;LOAD sqlstatement,if(quoteCount=0,part,if(previous(quoteCount)=0,part,previous(part) &amp;amp; '$(seperator)' &amp;amp; part)) as part;&lt;BR /&gt;// checks whether seperator is in a string, or not&lt;BR /&gt;LOAD sqlstatement,part,mod(substringcount(part,chr(39)),2) as quoteCount;&lt;BR /&gt;// forms parts disregarding the seperator&lt;BR /&gt;LOAD sqlstatement,mid(sqlstatement, start, count) as part, start, count;&lt;BR /&gt;// disregards seperator string in parts&lt;BR /&gt;LOAD sqlstatement,if(newstatement=1,start,start+len('$(seperator)')) as start, if(newstatement=1,count,count-len('$(seperator)')) as count;&lt;BR /&gt;// determines start of each part in sqlstatement and characters to count in sqlstatement till the start of next part&lt;BR /&gt;LOAD sqlstatement,if(isnull(previous(start)) or newstatement=1,1,previous(start)) as start, if(start=0,len(sqlstatement)+1,start)-if(isnull(previous(start)),1,previous(start)) as count,newstatement;&lt;BR /&gt;// splits sqlstatement into lines by using seperator variable&lt;BR /&gt;LOAD sqlstatement,if(previous(sqlstatement)&amp;lt;&amp;gt;sqlstatement,1,0) as newstatement,Index(sqlstatement,'$(seperator)', IterNo()) as start while IterNo() &amp;lt;= substringCount(sqlstatement,'$(seperator)')+1;&lt;BR /&gt;LOAD * Resident $(tablename);&lt;/P&gt;&lt;P&gt;drop field sqlstatement from $(tablename)_New;&lt;BR /&gt;drop table $(tablename);&lt;BR /&gt;rename table $(tablename)_New to $(tablename);&lt;BR /&gt;rename field filter to sqlstatement;&lt;/P&gt;&lt;P&gt;end sub&lt;/P&gt;&lt;P&gt;Input:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;sqlstatement&lt;BR /&gt;"record_number = 10 and currency = 'USD' and date=2020-09-30"&lt;BR /&gt;"record_number = 5 and currency = 'USD' and date=2020-5-11"&lt;BR /&gt;"date = '$date' and record_number = 4 and code = 'abc' and segment = 'SUB' and product='pr1 and pr2'"&lt;BR /&gt;"date =date=2121-09-30 and record_number = 5 or code = 'abc' and segment in ('IWM','SRU','SUB','GM and AP','Cor_Centr')"&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;call replaceStatement('Input',' and ',' &amp;amp; ');&lt;BR /&gt;call replaceStatement('Input',' or ', ' || ');&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 07:01:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/replace-and-in-string/m-p/1735853#M56229</guid>
      <dc:creator>SerhanKaraer</dc:creator>
      <dc:date>2020-08-14T07:01:08Z</dc:date>
    </item>
  </channel>
</rss>

