<?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 How to write multiple 'Contains' in SQL query in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-write-multiple-Contains-in-SQL-query/m-p/212233#M42480</link>
    <description>&lt;DIV class="forum-topic-flex-article"&gt;&lt;DIV class="forum-article"&gt;&lt;DIV class="forum-post"&gt;&lt;DIV class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hello everybody.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say I have an array with strings that are values of rows that I need to pull from DB. Let's say the array is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;searchStringArray = {'qwe', 'rty', 'asd',' fgh', 'zxc'}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I can construct my WHERE statement in my query in a pretty simple way:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"WHERE 
t1.column1 IN (' " || Concat Items(searchStringsArray, " ', ' ")|| " ' )"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;which when parsed would give me the following string:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"WHERE
t1.column1 IN('qwe', 'rty', 'asd', 'fgh', 'zxc')"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But what if my searchStringArray has not full strings but partial strings?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to simplify my script. Currently I have a query that has multiple Contains statements, which in SQL looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"WHERE&lt;BR /&gt;(t1.column1 LIKE '%qwe%') OR
(t1.column1 LIKE '%rty%') OR
(t1.column1 LIKE '%asd%') OR
(t1.column1 LIKE '%fgh%') OR
(t1.column1 LIKE '%zxc%')"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is pretty cumbersome to construct from a string array. I was wondering if I can write an equivalent WHERE statement that looks something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"WHERE
t1.column1 IN ('%qwe%', '%rty%', '%asd%', '%fgh%', '%zxc%')"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"WHERE
t1.column1 MATCH('%qwe%' OR '%rty%' OR '%asd%' OR '%fgh%' OR '%zxc%')"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or something similar that would be easier to construct using&amp;nbsp;&lt;CODE class=" language-jsl"&gt;Concat Items()&lt;/CODE&gt;. I tried two examples above, although they seem to be valid SQLite syntax, they do not work in JSL. Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;M&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="KudosButton lia-button-image-kudos-wrapper lia-component-kudos-widget-button-version-3 lia-component-kudos-widget-button-horizontal lia-component-kudos-widget-button lia-component-kudos-action lia-component-message-view-widget-kudos-action"&gt;&lt;DIV class="lia-button-image-kudos lia-button-image-kudos-horizontal lia-button-image-kudos-disabled lia-button-image-kudos-not-kudoed lia-button"&gt;&lt;DIV class="lia-button-image-kudos-give"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 06 Jun 2019 21:31:41 GMT</pubDate>
    <dc:creator>miguello</dc:creator>
    <dc:date>2019-06-06T21:31:41Z</dc:date>
    <item>
      <title>How to write multiple 'Contains' in SQL query</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-multiple-Contains-in-SQL-query/m-p/212233#M42480</link>
      <description>&lt;DIV class="forum-topic-flex-article"&gt;&lt;DIV class="forum-article"&gt;&lt;DIV class="forum-post"&gt;&lt;DIV class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hello everybody.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's say I have an array with strings that are values of rows that I need to pull from DB. Let's say the array is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;searchStringArray = {'qwe', 'rty', 'asd',' fgh', 'zxc'}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I can construct my WHERE statement in my query in a pretty simple way:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"WHERE 
t1.column1 IN (' " || Concat Items(searchStringsArray, " ', ' ")|| " ' )"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;which when parsed would give me the following string:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"WHERE
t1.column1 IN('qwe', 'rty', 'asd', 'fgh', 'zxc')"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But what if my searchStringArray has not full strings but partial strings?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to simplify my script. Currently I have a query that has multiple Contains statements, which in SQL looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"WHERE&lt;BR /&gt;(t1.column1 LIKE '%qwe%') OR
(t1.column1 LIKE '%rty%') OR
(t1.column1 LIKE '%asd%') OR
(t1.column1 LIKE '%fgh%') OR
(t1.column1 LIKE '%zxc%')"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is pretty cumbersome to construct from a string array. I was wondering if I can write an equivalent WHERE statement that looks something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"WHERE
t1.column1 IN ('%qwe%', '%rty%', '%asd%', '%fgh%', '%zxc%')"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"WHERE
t1.column1 MATCH('%qwe%' OR '%rty%' OR '%asd%' OR '%fgh%' OR '%zxc%')"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or something similar that would be easier to construct using&amp;nbsp;&lt;CODE class=" language-jsl"&gt;Concat Items()&lt;/CODE&gt;. I tried two examples above, although they seem to be valid SQLite syntax, they do not work in JSL. Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;M&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="KudosButton lia-button-image-kudos-wrapper lia-component-kudos-widget-button-version-3 lia-component-kudos-widget-button-horizontal lia-component-kudos-widget-button lia-component-kudos-action lia-component-message-view-widget-kudos-action"&gt;&lt;DIV class="lia-button-image-kudos lia-button-image-kudos-horizontal lia-button-image-kudos-disabled lia-button-image-kudos-not-kudoed lia-button"&gt;&lt;DIV class="lia-button-image-kudos-give"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 06 Jun 2019 21:31:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-multiple-Contains-in-SQL-query/m-p/212233#M42480</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2019-06-06T21:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to write multiple 'Contains' in SQL query</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-multiple-Contains-in-SQL-query/m-p/212254#M42483</link>
      <description>&lt;P&gt;What are you actually trying to do?&amp;nbsp; Select some rows in a JMP data table?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 23:47:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-multiple-Contains-in-SQL-query/m-p/212254#M42483</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2019-06-06T23:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to write multiple 'Contains' in SQL query</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-multiple-Contains-in-SQL-query/m-p/212256#M42485</link>
      <description>&lt;P&gt;Use SIMILAR TO. For syntax, the below statements do the same thing. Of course, you'll have to type the "SIMILAR TO" statement in as a "custom expression" in the JMP query builder filters section. I don't think you can generate it by clicking items in the red triangle menu.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;P class="1559865335060"&gt;WHERE (&amp;nbsp; ("t1".column1 LIKE '%AAA%' ) OR ( "t1".column1 LIKE '%BBB%' ) )&lt;/P&gt;&lt;P class="1559865335060"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="1559865335060"&gt;WHERE (&amp;nbsp; ("t1".column1 SIMILAR TO&amp;nbsp;'%(AAA|BBB)%' &amp;nbsp;) )&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 07 Jun 2019 00:02:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-multiple-Contains-in-SQL-query/m-p/212256#M42485</guid>
      <dc:creator>WhiteMenCanJMP</dc:creator>
      <dc:date>2019-06-07T00:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to write multiple 'Contains' in SQL query</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-multiple-Contains-in-SQL-query/m-p/212338#M42511</link>
      <description>It's pretty much stated in the first sentence of the question.&lt;BR /&gt;I need to dynamically construct a query string to pull data from DB. List of search terms and column name are dynamic. For one of the column names the match is not exact, so I can't use WHERE t1.column1 IN ('qwe', 'rty'...) and so on. Instead, I had to use LIKE keyword and very bulky construct. I was looking for a construct that is similar to (pun intended) IN in syntax. This keyword is 'SIMILAR TO'.&lt;BR /&gt;</description>
      <pubDate>Fri, 07 Jun 2019 16:41:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-multiple-Contains-in-SQL-query/m-p/212338#M42511</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2019-06-07T16:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to write multiple 'Contains' in SQL query</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-multiple-Contains-in-SQL-query/m-p/212351#M42517</link>
      <description>&lt;P&gt;Looks like it's working as promised. It produces identical to my current solution results.&lt;/P&gt;&lt;P&gt;I use it in JSL, where I assemble the query string out of some text and variable. For instance, t1.column1 is also a variable, and I have partial matches for only one of those variables for t1.column1, so I had to use something like this for one variable:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"WHERE(t1.column1 LIKE '%qwe%') OR
(t1.column1 LIKE '%rty%') OR
(t1.column1 LIKE '%asd%') OR
(t1.column1 LIKE '%fgh%') OR
(t1.column1 LIKE '%zxc%')"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;making it a pretty complex thing to assemble something like that from&amp;nbsp;&lt;CODE class=" language-jsl"&gt;stringColumnName = "column1"&lt;/CODE&gt; and&amp;nbsp;&lt;CODE class=" language-jsl"&gt;searchStringArray = {'qwe', 'rty', 'asd',' fgh', 'zxc'}&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While for other column variables it comes to much simpler form of:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;"WHERE 
t1."||stringColumnName||" IN (' "||Concat Items(searchStringsArray," ', ' ")||" ' )"&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now, thanks to&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/8242"&gt;@WhiteMenCanJMP&lt;/a&gt;&amp;nbsp; and his SIMILAR TO this task of assembling dynamic query string is going to be much simpler.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And no worries about custom window - I script that in JSL anyways. Although Custom filter in Query Builder is the fastest way to check syntax anyways.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 17:29:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-multiple-Contains-in-SQL-query/m-p/212351#M42517</guid>
      <dc:creator>miguello</dc:creator>
      <dc:date>2019-06-07T17:29:38Z</dc:date>
    </item>
  </channel>
</rss>

