<?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 query to ODBC datasource / SQL server with temporary tables in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/m-p/458161#M70334</link>
    <description>&lt;P&gt;Jane,&lt;/P&gt;
&lt;P&gt;If you modify your first SQL to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;query= "SET NOCOUNT ON;
CREATE TABLE #tmpTable (ID int PRIMARY KEY NOT NULL, WaferNum int NOT NULL);
INSERT INTO #tmpTable (ID, WaferNum) (
SELECT
ID,
WaferNum
FROM WareHouse
);
SELECT * FROM #tmpTable;
DROP TABLE #tmpTable;
";

dbc = Create Database Connection(
"DSN=DatabaseName; ... ; UID=email@abc.com;"
);
Execute SQL (dbc, query);
close database connection(dbc);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You should get the table into JMP.&lt;/P&gt;
&lt;P&gt;The addition, (in case it got lost in the JSL) is:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SET NOCOUNT ON;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/sql/t-sql/statements/set-nocount-transact-sql?view=sql-server-ver15" target="_blank"&gt;https://docs.microsoft.com/en-us/sql/t-sql/statements/set-nocount-transact-sql?view=sql-server-ver15&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;-Bryan&lt;/P&gt;</description>
    <pubDate>Thu, 03 Feb 2022 15:50:39 GMT</pubDate>
    <dc:creator>bryan_boone</dc:creator>
    <dc:date>2022-02-03T15:50:39Z</dc:date>
    <item>
      <title>SQL query to ODBC datasource / SQL server with temporary tables</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/m-p/457582#M70262</link>
      <description>&lt;P&gt;Dear Community,&lt;/P&gt;
&lt;P&gt;I am building a SQL script where utilizing temporary tables at SQL server. Simplified example script below (which works fine elsewhere) runs without error but does NOT return any data (ie. JMP data table does not pop up).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;query= "
CREATE TABLE #tmpTable (ID int PRIMARY KEY NOT NULL, WaferNum int NOT NULL);
INSERT INTO #tmpTable (ID, WaferNum) (
SELECT
ID,
WaferNum
FROM WareHouse
);
SELECT * FROM #tmpTable;
DROP TABLE #tmpTable;
";

dbc = Create Database Connection(
"DSN=DatabaseName; ... ; UID=email@abc.com;"
);
Execute SQL (dbc, query);
close database connection(dbc);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My next iteration was to split the execution as below; this trick was mentioned on some thread.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;query1= "
CREATE TABLE #tmpTable (ID int PRIMARY KEY NOT NULL, WaferNum int NOT NULL);
INSERT INTO #tmpTable (ID, WaferNum) (
SELECT
ID,
WaferNum
FROM WareHouse
);
";
query2= "
SELECT * FROM #tmpTable
DROP TABLE #tmpTable;
";
query3= "
DROP TABLE #tmpTable;
";
dbc = Create Database Connection(
"DSN=DatabaseName; ... ; UID=email@abc.com;"
);
Execute SQL (dbc, query1);
Execute SQL (dbc, query2, "Table");
Execute SQL (dbc, query3);
close database connection(dbc);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now JMP log window captures messages from SQL server (without returned data): &lt;FONT color="#0000FF"&gt;&lt;EM&gt;Invalid object name #tmpTable&lt;/EM&gt;&lt;/FONT&gt; and &lt;EM&gt;&lt;FONT color="#0000FF"&gt;Cannot drop the table&amp;nbsp;#tmpTable as does not exist.&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;I am running JMP16. Any advices are highly appreciated.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:43:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/m-p/457582#M70262</guid>
      <dc:creator>JanneI</dc:creator>
      <dc:date>2023-06-10T23:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query to ODBC datasource / SQL server with temporary tables</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/m-p/457637#M70271</link>
      <description>&lt;P&gt;Hi Jannel,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm hoping it is not this old issue&amp;nbsp;&lt;LI-MESSAGE title="Importing SQL using a temp table" uid="11760" url="https://community.jmp.com/t5/Discussions/Importing-SQL-using-a-temp-table/m-p/11760#U11760" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;. Hopefully someone else on the forum has used SQL Server Temp tables more recently with JMP.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Brian Corcoran&lt;/P&gt;
&lt;P&gt;JMP Development&lt;/P&gt;</description>
      <pubDate>Wed, 02 Feb 2022 12:29:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/m-p/457637#M70271</guid>
      <dc:creator>briancorcoran</dc:creator>
      <dc:date>2022-02-02T12:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query to ODBC datasource / SQL server with temporary tables</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/m-p/458027#M70319</link>
      <description>&lt;P&gt;Hi Brian, Thanks for pointing the old thread; indeed very related. Fascinating issue!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did some debugging by looking the logs on test SQL Server I have established on my laptop. First note is that same query (with temporary tables or table variables) executed using very same DNS connection / ODBC driver in Excel works fine but not from JMP. When looking the incoming traffic to server, Excel sends the query string as it is (eg &lt;CODE class=" language-jsl"&gt;SELECT * FROM Table&lt;/CODE&gt;)&amp;nbsp; but from JMP, query arrives in format:&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;declare @p1 int
set @p1=1
exec sp_prepexec @p1 output,NULL,N'SELECT * FROM Table'
select @p1&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe that the SQL statement is wrapped with extra stuff by ODBC driver. Especially the&amp;nbsp;system&lt;SPAN&gt;&amp;nbsp;stored procedure&lt;/SPAN&gt;&amp;nbsp;&lt;CODE class=" language-jsl"&gt;sp_prepexec&lt;/CODE&gt;&amp;nbsp;looks to be the one causing issues. May or may not be related to quotation marks; difficult to say what really happens inside that procedure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ok, it is ODBC driver issue. However, as far as know, ODBC enables also direct execution. I believe this is what happens with Excel. Could this same be possible also with JMP? Couple related links below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://techcommunity.microsoft.com/t5/datacat/watch-out-those-prepared-sql-statements/ba-p/305074" target="_blank"&gt;https://techcommunity.microsoft.com/t5/datacat/watch-out-those-prepared-sql-statements/ba-p/305074&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/direct-execution-odbc?view=sql-server-ver15" target="_blank"&gt;https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/direct-execution-odbc?view=sql-server-ver15&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 12:33:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/m-p/458027#M70319</guid>
      <dc:creator>JanneI</dc:creator>
      <dc:date>2022-02-03T12:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query to ODBC datasource / SQL server with temporary tables</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/m-p/458161#M70334</link>
      <description>&lt;P&gt;Jane,&lt;/P&gt;
&lt;P&gt;If you modify your first SQL to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;query= "SET NOCOUNT ON;
CREATE TABLE #tmpTable (ID int PRIMARY KEY NOT NULL, WaferNum int NOT NULL);
INSERT INTO #tmpTable (ID, WaferNum) (
SELECT
ID,
WaferNum
FROM WareHouse
);
SELECT * FROM #tmpTable;
DROP TABLE #tmpTable;
";

dbc = Create Database Connection(
"DSN=DatabaseName; ... ; UID=email@abc.com;"
);
Execute SQL (dbc, query);
close database connection(dbc);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You should get the table into JMP.&lt;/P&gt;
&lt;P&gt;The addition, (in case it got lost in the JSL) is:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;SET NOCOUNT ON;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/sql/t-sql/statements/set-nocount-transact-sql?view=sql-server-ver15" target="_blank"&gt;https://docs.microsoft.com/en-us/sql/t-sql/statements/set-nocount-transact-sql?view=sql-server-ver15&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;-Bryan&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 15:50:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/m-p/458161#M70334</guid>
      <dc:creator>bryan_boone</dc:creator>
      <dc:date>2022-02-03T15:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query to ODBC datasource / SQL server with temporary tables</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/m-p/458283#M70339</link>
      <description>&lt;P&gt;Hi Bryan,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your solution&amp;nbsp;&lt;EM&gt;SET NOCOUNT ON;&lt;/EM&gt; works great!!! I am amazed how easy the solution was. I have spent quite some time by looking the solution from various forums and threads but no one has suggested this one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Great thanks;&lt;/P&gt;&lt;P&gt;Janne&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 19:45:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/m-p/458283#M70339</guid>
      <dc:creator>JanneI</dc:creator>
      <dc:date>2022-02-03T19:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: SQL query to ODBC datasource / SQL server with temporary tables</title>
      <link>https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/m-p/458284#M70340</link>
      <description>&lt;P&gt;SET NOCOUNT ON is an odd option indeed.&lt;BR /&gt;Glad it worked out for you!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 19:52:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/SQL-query-to-ODBC-datasource-SQL-server-with-temporary-tables/m-p/458284#M70340</guid>
      <dc:creator>bryan_boone</dc:creator>
      <dc:date>2022-02-03T19:52:37Z</dc:date>
    </item>
  </channel>
</rss>

