<?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 Eval insert SQL in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/572310#M78161</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;i am trying to produce an SQL statment that will bring only rows with matching id names.&lt;/P&gt;
&lt;P&gt;i have a userlist that i want to Eval insert into the SQL string. problem is that it parses it with double quotes instead of single quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here (1);&lt;BR /&gt;// got the userlist from a data table using dt:users &amp;lt;&amp;lt; get as matrix&lt;BR /&gt;userlist  = {"01E1B5C0651EDA80", "F62B70921920FCBE", "909D35028E2039CE", "B339888591CF1346"};
&lt;BR /&gt;// define an SQL string to host the list of user ids
sqlstr_ =
"SELECT  \!"t1\!".uid 
FROM \!"Tables\!".\!"Table\!"  \!"t1\!"
WHERE  ( \!"t1\!".uid IN ( ^userlist^) )
;";

Eval Insert( sqlstr_logs );
// i get the following non working SQL string 
"SELECT  \!"t1\!".uid
FROM \!"Tables\!".\!"Table\!"  \!"t1\!"
WHERE  ( \!"t1\!".uid IN ( {\!"01E1B5C0651EDA80\!", \!"F62B70921920FCBE\!", \!"909D35028E2039CE\!", }) )
;"
// i would like to get the following working SQL statement
"SELECT \!"t1\!".uid 
FROM \!"Tables\!".\!"Table\!"  \!"t1\!" 
WHERE  ( \!"t1\!".uid IN  ( '01E1B5C0651EDA80' ,  'F62B70921920FCBE' ,  'F62B70921920FCBE' )  ) ;"




&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;thank you very much in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jun 2023 16:02:49 GMT</pubDate>
    <dc:creator>ron_horne</dc:creator>
    <dc:date>2023-06-09T16:02:49Z</dc:date>
    <item>
      <title>Eval insert SQL</title>
      <link>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/572310#M78161</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;i am trying to produce an SQL statment that will bring only rows with matching id names.&lt;/P&gt;
&lt;P&gt;i have a userlist that i want to Eval insert into the SQL string. problem is that it parses it with double quotes instead of single quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here (1);&lt;BR /&gt;// got the userlist from a data table using dt:users &amp;lt;&amp;lt; get as matrix&lt;BR /&gt;userlist  = {"01E1B5C0651EDA80", "F62B70921920FCBE", "909D35028E2039CE", "B339888591CF1346"};
&lt;BR /&gt;// define an SQL string to host the list of user ids
sqlstr_ =
"SELECT  \!"t1\!".uid 
FROM \!"Tables\!".\!"Table\!"  \!"t1\!"
WHERE  ( \!"t1\!".uid IN ( ^userlist^) )
;";

Eval Insert( sqlstr_logs );
// i get the following non working SQL string 
"SELECT  \!"t1\!".uid
FROM \!"Tables\!".\!"Table\!"  \!"t1\!"
WHERE  ( \!"t1\!".uid IN ( {\!"01E1B5C0651EDA80\!", \!"F62B70921920FCBE\!", \!"909D35028E2039CE\!", }) )
;"
// i would like to get the following working SQL statement
"SELECT \!"t1\!".uid 
FROM \!"Tables\!".\!"Table\!"  \!"t1\!" 
WHERE  ( \!"t1\!".uid IN  ( '01E1B5C0651EDA80' ,  'F62B70921920FCBE' ,  'F62B70921920FCBE' )  ) ;"




&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;thank you very much in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:02:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/572310#M78161</guid>
      <dc:creator>ron_horne</dc:creator>
      <dc:date>2023-06-09T16:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Eval insert SQL</title>
      <link>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/572343#M78163</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;userlist= {"01E1B5C0651EDA80", "F62B70921920FCBE", "909D35028E2039CE"};
sqlstr_ =
"SELECT  \!"t1\!".uid 
FROM \!"Tables\!".\!"Table\!"  \!"t1\!"
WHERE  ( \!"t1\!".uid IN ( '^
concatitems(userlist,\!"','\!")
^') )
;";

write(Eval Insert( sqlstr_ ));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The leading and trailing apostrophes are handled differently from the interior apostrophes; see just before and after the ^, vs the separator string. If there is any possibility userlist could have 0 items, you should check for that before running the query because it will probably not make any sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can make it a little more readable using the other escape mechanism (html does not know about it so the syntax coloring is wrong on the web):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;userlist= {"01E1B5C0651EDA80", "F62B70921920FCBE", "909D35028E2039CE"};
sqlstr_ =
"\[
SELECT  "t1".uid 
FROM "Tables"."Table"  "t1"
WHERE  ( "t1".uid IN ( '^
concatitems(userlist,"','")
^') );
]\";

write(Eval Insert( sqlstr_ ));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using write() to display the result helps too:&lt;/P&gt;
&lt;PRE&gt;SELECT  "t1".uid 
FROM "Tables"."Table"  "t1"
WHERE  ( "t1".uid IN ( '01E1B5C0651EDA80','F62B70921920FCBE','909D35028E2039CE') );&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 01:15:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/572343#M78163</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2022-11-23T01:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Eval insert SQL</title>
      <link>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/572465#M78166</link>
      <description>&lt;P&gt;thank you &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt; , this is very helpful. &lt;/P&gt;
&lt;P&gt;the eval insert now works correctly. with respect to the other escape mechanism, it is much easier. pity this is not the way the software writes it.&lt;BR /&gt;I have another issue with SQL. i would like to get rows only where the value is made out of 16 alphanumeric characters.&lt;/P&gt;
&lt;P&gt;the length statement by itself works fine. the regex doesn't&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;sqlstr_uid =
"\[
SELECT DISTINCT "t1".uid 
FROM "Tables"."Table"  "t1" 
WHERE ( (LENGTH	( "t1".uid) = 16) AND (  "t1".uid REGEXP '^[A-Za-z0-9]+$' ) )

]\";
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;am i missing a = or brackets?&lt;/P&gt;
&lt;P&gt;thanks again!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 11:25:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/572465#M78166</guid>
      <dc:creator>ron_horne</dc:creator>
      <dc:date>2022-11-23T11:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: Eval insert SQL</title>
      <link>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/573001#M78186</link>
      <description>&lt;P&gt;Looking at some random sites on the web, it looks right. I'm not an SQL expert though.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 19:45:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/573001#M78186</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2022-11-23T19:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Eval insert SQL</title>
      <link>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/573024#M78193</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/958"&gt;@ron_horne&lt;/a&gt;,&amp;nbsp;try REGEXP_LIKE&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 20:49:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/573024#M78193</guid>
      <dc:creator>ErraticAttack</dc:creator>
      <dc:date>2022-11-23T20:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: Eval insert SQL</title>
      <link>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/573159#M78210</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/26363"&gt;@ErraticAttack&lt;/a&gt; ,&lt;/P&gt;
&lt;P&gt;it didn't work. i did manage to use this expression:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;regexp_substr("t1".uid, '^[A-Za-z0-9]+$')="t1".uid )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Nov 2022 12:02:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/573159#M78210</guid>
      <dc:creator>ron_horne</dc:creator>
      <dc:date>2022-11-24T12:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Eval insert SQL</title>
      <link>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/585220#M79092</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;the following regex expression works when submitting the sql statement as a string:&lt;BR /&gt;regexp_substr("t1".uid, '^[A-Za-z0-9]+$')="t1".uid )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;yet, when submitting this expression using eval insert (sql_str) i get an error.&lt;BR /&gt;the error has to do with the [ so i assume that evel insert is having a hard time with the ^ just before it.&lt;BR /&gt;is there a way of escaping the ^&amp;nbsp; ?&lt;BR /&gt;the following shows the exact error.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;sqlstr_uid =
"\[
SELECT DISTINCT "t1".uid 
FROM "Tables"."Table"  "t1" 
WHERE    "t1".uid REGEXP '^[A-Za-z0-9]+$' 
]\";

write(Eval Insert( sqlstr_uid ));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;many thanks!&lt;/P&gt;
&lt;P&gt;ron&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2022 20:32:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/585220#M79092</guid>
      <dc:creator>ron_horne</dc:creator>
      <dc:date>2022-12-25T20:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: Eval insert SQL</title>
      <link>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/585221#M79093</link>
      <description>&lt;P&gt;You can define which character to use with Eval Insert and I would suggest using some other character than default ^ if you are evaluating sql strings (especially ones with regex), I usually use "¤"&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

sqlstr_uid =
"\[
SELECT DISTINCT "t1".uid 
FROM "Tables"."Table"  "t1" 
WHERE    "t1".uid REGEXP '^[A-Za-z0-9]+$' 
]\";

Write(Eval Insert(sqlstr_uid, "¤"));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 25 Dec 2022 20:55:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/585221#M79093</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-12-25T20:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Eval insert SQL</title>
      <link>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/585224#M79094</link>
      <description>&lt;P&gt;thank you very much &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt; this is perfect!&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2022 21:38:58 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/585224#M79094</guid>
      <dc:creator>ron_horne</dc:creator>
      <dc:date>2022-12-25T21:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: Eval insert SQL</title>
      <link>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/585225#M79095</link>
      <description>&lt;P&gt;Similar example&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;sqlstr_uid =
"\[
SELECT DISTINCT "t1".uid 
FROM "Tables"."Table"  "t1" 
WHERE    "t1".uid REGEXP '^[A-Za-z0-9]+$' 
]\";

write(Eval Insert( "the test ☺sqlstr_uid☺ works", "☺" ));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;the test &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;SELECT DISTINCT "t1".uid &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;FROM "Tables"."Table" "t1" &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;WHERE "t1".uid REGEXP '^[A-Za-z0-9]+$' &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;works&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;There does not appear to be a \! escaping mechanism in Eval Insert; you need to pick an unused character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Dec 2022 21:45:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Eval-insert-SQL/m-p/585225#M79095</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2022-12-25T21:45:26Z</dc:date>
    </item>
  </channel>
</rss>

