<?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: Check if table exist on sql db in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Check-if-table-exist-on-sql-db/m-p/441658#M68997</link>
    <description>&lt;P&gt;it returns a table, how to get an argument? boolean ?&lt;/P&gt;</description>
    <pubDate>Thu, 02 Dec 2021 13:23:42 GMT</pubDate>
    <dc:creator>geoff1</dc:creator>
    <dc:date>2021-12-02T13:23:42Z</dc:date>
    <item>
      <title>Check if table exist on sql db</title>
      <link>https://community.jmp.com/t5/Discussions/Check-if-table-exist-on-sql-db/m-p/441602#M68987</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am running some jmpquery on different SQL DB. Because some DB do not have the same tables,&amp;nbsp; I getting the error:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Tables (public.table1(t1)) referenced in the SQL Query were not found in the database{1} in access or evaluation of 'Table' , Table( "table1", Schema( "public" ), Alias( "t1" ) ) /*###*/&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How could I check if a table exists on a SQL DB before running a query ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Geof&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 18:06:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Check-if-table-exist-on-sql-db/m-p/441602#M68987</guid>
      <dc:creator>geoff1</dc:creator>
      <dc:date>2023-06-09T18:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exist on sql db</title>
      <link>https://community.jmp.com/t5/Discussions/Check-if-table-exist-on-sql-db/m-p/441657#M68996</link>
      <description>&lt;P&gt;I found using the custom SQL below, it returns 0 or 1 if it exists.&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 );
obj = New SQL Query(
	Connection( "ODBC:DSN=xxxx" ),
	Custom SQL(
		"SELECT EXISTS (
SELECT FROM information_schema.tables
WHERE table_schema = 'public'
AND table_name = 'table1'
);"
	)
);
obj &amp;lt;&amp;lt; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Dec 2021 13:50:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Check-if-table-exist-on-sql-db/m-p/441657#M68996</guid>
      <dc:creator>geoff1</dc:creator>
      <dc:date>2021-12-02T13:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exist on sql db</title>
      <link>https://community.jmp.com/t5/Discussions/Check-if-table-exist-on-sql-db/m-p/441658#M68997</link>
      <description>&lt;P&gt;it returns a table, how to get an argument? boolean ?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Dec 2021 13:23:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Check-if-table-exist-on-sql-db/m-p/441658#M68997</guid>
      <dc:creator>geoff1</dc:creator>
      <dc:date>2021-12-02T13:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exist on sql db</title>
      <link>https://community.jmp.com/t5/Discussions/Check-if-table-exist-on-sql-db/m-p/441777#M69008</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;argument = N Rows(dt);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;returns the number of rows of the table. If there is no row, the table was not there&lt;/P&gt;</description>
      <pubDate>Thu, 02 Dec 2021 18:18:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Check-if-table-exist-on-sql-db/m-p/441777#M69008</guid>
      <dc:creator>Georg</dc:creator>
      <dc:date>2021-12-02T18:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: Check if table exist on sql db</title>
      <link>https://community.jmp.com/t5/Discussions/Check-if-table-exist-on-sql-db/m-p/441779#M69009</link>
      <description>&lt;P&gt;If this is SQL Server something like this (untested) should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

schema_name = "PUBLIC";
table_name  = "TABLE1";

sql = evalinsert(
"SELECT COUNT(*) N
   FROM information_schema.tables
  WHERE table_schema = '^schema_name^'
    AND table_name = '^table_name^'");

dbc = create database connection("ODBC:DSN=xxxx");
dt = execute sql(dbc, sql, invisible);
close database connection(dbc);
ntables = dt:N[1];
if (ntables,
	print("Table " || table_name || " exists");
	,
	print("Table " || table_name || " does not exist");
);&lt;BR /&gt;close(dt,&amp;nbsp;nosave);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Dec 2021 19:41:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Check-if-table-exist-on-sql-db/m-p/441779#M69009</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2021-12-02T19:41:31Z</dc:date>
    </item>
  </channel>
</rss>

