<?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: SQL - cannot insert multiple comands into prepared statement in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/629450#M82765</link>
    <description>&lt;P&gt;i get the same error if i try it using the following script:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// connect to database - open data base
DBConnection = Create Database Connection(
"ODBC:DSN=database-project;EPWD=.....;");

sql_events = 
"\[
select * from "public"."logs"  "t1";
select * from "public"."logs"  "t1";
]\"
dt1 = execute sql ( DBConnection,  eval insert ( sql_events , "¤") ,  "Events from logs"  );
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the issue may be similar to this discussion:&lt;BR /&gt;&lt;A href="https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/td-p/457582" target="_blank"&gt;https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/td-p/457582&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;but the solution there is not exactly applicable to redshift.&lt;/P&gt;</description>
    <pubDate>Sat, 06 May 2023 20:09:18 GMT</pubDate>
    <dc:creator>ron_horne</dc:creator>
    <dc:date>2023-05-06T20:09:18Z</dc:date>
    <item>
      <title>SQL - cannot insert multiple comands into prepared statement</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/629346#M82757</link>
      <description>&lt;P&gt;dear members of the forum,&lt;BR /&gt;when using jmp to query amazon redshift i need to send two statements together but for some reason this i get an error saying:&lt;BR /&gt;&lt;BR /&gt;unfortunately, my query is very elaborate and doesn't work with just a "Where" statement for each separate table.&lt;BR /&gt;if anyone has any idea how to overcome this issue it would be helpful.&lt;/P&gt;
&lt;P&gt;Thanks &lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ron_horne_0-1683372905784.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/52607i74EF26A22BE2365F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ron_horne_0-1683372905784.png" alt="ron_horne_0-1683372905784.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 20:55:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/629346#M82757</guid>
      <dc:creator>ron_horne</dc:creator>
      <dc:date>2023-06-10T20:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: SQL - cannot insert multiple comands into prepared statement</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/629386#M82760</link>
      <description>&lt;P&gt;Dear Ron, I did Not Do This so far, but here you are asking new sql query for two tables, I suppose, it can not handle that. Did you try execute sql instead?&lt;/P&gt;&lt;P&gt;Other possibility would be union between both queries to have one only. But this requires exactly the same columns in same order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 May 2023 14:51:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/629386#M82760</guid>
      <dc:creator>Georg</dc:creator>
      <dc:date>2023-05-06T14:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: SQL - cannot insert multiple comands into prepared statement</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/629450#M82765</link>
      <description>&lt;P&gt;i get the same error if i try it using the following script:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// connect to database - open data base
DBConnection = Create Database Connection(
"ODBC:DSN=database-project;EPWD=.....;");

sql_events = 
"\[
select * from "public"."logs"  "t1";
select * from "public"."logs"  "t1";
]\"
dt1 = execute sql ( DBConnection,  eval insert ( sql_events , "¤") ,  "Events from logs"  );
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the issue may be similar to this discussion:&lt;BR /&gt;&lt;A href="https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/td-p/457582" target="_blank"&gt;https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/td-p/457582&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;but the solution there is not exactly applicable to redshift.&lt;/P&gt;</description>
      <pubDate>Sat, 06 May 2023 20:09:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/629450#M82765</guid>
      <dc:creator>ron_horne</dc:creator>
      <dc:date>2023-05-06T20:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: SQL - cannot insert multiple comands into prepared statement</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/629513#M82771</link>
      <description>&lt;P&gt;Generally you can't execute two SQL statements with one call to EXECUTE SQL.&amp;nbsp; Both statements are the same; perhaps you were just showing an example?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why are you trying to run two SQL statements at once?&amp;nbsp; EXECUTE SQL returns a dataset for each SQL statement.&lt;/P&gt;
&lt;P&gt;Why not just run two EXECUTE SQL commands?&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 00:46:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/629513#M82771</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2023-05-08T00:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: SQL - cannot insert multiple comands into prepared statement</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/630361#M82852</link>
      <description>&lt;P&gt;you are right &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4550"&gt;@pmroz&lt;/a&gt; , it was just an example of two statements.&lt;BR /&gt;sometimes i need two statements to create a sub-sample (temporary table) or define a function.&lt;BR /&gt;in most cases i manage to use the "With" statement instead of a temporary table but not always. especially when using the "With" statements requires very complex sub-queries that are not allowed. &amp;nbsp; .&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2023 20:15:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/630361#M82852</guid>
      <dc:creator>ron_horne</dc:creator>
      <dc:date>2023-05-09T20:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: SQL - cannot insert multiple comands into prepared statement</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/630374#M82853</link>
      <description>&lt;P&gt;This approach might help:&lt;/P&gt;
&lt;P&gt;Call a PL/SQL procedure that does the super-complex query, and creates a temporary table.&lt;/P&gt;
&lt;P&gt;Then select * from the temporary table.&lt;/P&gt;
&lt;P&gt;Here's some code that does something like that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;event_sql = evalinsert(
"DECLARE 
	l_proc_name VARCHAR2 (100)	:= 'Get_Reference_PTs'; 
	l_user_SID 	NUMBER			:= SYS_CONTEXT('USERENV', 'SID'); 
	l_user_name	VARCHAR2 (30)	:= UPPER(SYS_CONTEXT('USERENV', 'OS_USER')); 
BEGIN 

    INSERT INTO quality_attrib (SID, OS_USER, Completion_Time, Progress_Text) 
        VALUES (l_user_SID, l_user_name, SYSTIMESTAMP, 'START Get_Reference_PTs');  
        COMMIT; 

	INSERT INTO Ref_PT_List (SID, OS_USER, PT_Name) 
	(SELECT DISTINCT l_user_SID, l_user_name, mu.pt_name 
	FROM info ci, 
		 drug cd, 
	     reaction cr, 
	     meddra_uta mu,  
	 WHERE cd.case_id = ci.case_id 
	   AND cr.case_id = ci.case_id 
	   AND cr.reported_meddra_uta_id = mu.meddra_uta_id 
	   AND cd.cdd_generic_id = rd.cdd_generic_id 
	   AND ci.report_type_code_id = 8  
	   AND rd.calendar_id =  ^one_calendar_id^
	   AND cd.drug_character_code_id IN (31, 32)
	^pt_clause^
	^date_clause^
	^event_type_clause^
	); 
	COMMIT; 

    INSERT INTO quality_attrib (SID, OS_USER, Completion_Time, Progress_Text) 
        VALUES (l_user_SID, l_user_name, SYSTIMESTAMP, 'END Get_Reference_PTs');  
        COMMIT; 

EXCEPTION 
    WHEN OTHERS 
        THEN 
        log_error_message(SQLCODE, SQLERRM, l_proc_name); 
END; ");

Execute SQL(dbc, event_sql);

Execute SQL(dbc, "select * from ref_pt_list");&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2023 20:33:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/630374#M82853</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2023-05-09T20:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: SQL - cannot insert multiple comands into prepared statement</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/636729#M83467</link>
      <description>&lt;P&gt;thank you very much &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/4550"&gt;@pmroz&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;splitting the two statements into separate Execute SQL statements works perfect.&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2023 11:18:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-cannot-insert-multiple-comands-into-prepared-statement/m-p/636729#M83467</guid>
      <dc:creator>ron_horne</dc:creator>
      <dc:date>2023-05-30T11:18:35Z</dc:date>
    </item>
  </channel>
</rss>

