<?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>Question Re: Sybase db.execute if exist in vb6 &amp; SQL in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827509#M4858352</link>
    <description>&lt;P&gt;As to the "if exists (...)" vs. " = 1" tests:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;EXISTS&lt;/STRONG&gt;&lt;BR /&gt;
&lt;/P&gt;
&lt;P&gt;The existence test (EXISTS) checks whether a subquery produces any rows of query results. If the subquery produces one or more rows of results, the EXISTS test returns TRUE. Otherwise, it returns FALSE. &lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's what you're about here: You simply want to check if there is at least one row for that table in the system catalog.&lt;/P&gt;
&lt;P&gt;The "= 1" would be useful if you would count the number of rows, i.e. for something like:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;if (select count(*) from sysobjects where name= 'mytable') = 1 then ... end if;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
    <pubDate>Tue, 15 May 2012 03:27:45 GMT</pubDate>
    <dc:creator>VolkerBarth</dc:creator>
    <dc:date>2012-05-15T03:27:45Z</dc:date>
    <item>
      <title>Sybase db.execute if exist in vb6 &amp; SQL</title>
      <link>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaq-p/13827505</link>
      <description>&lt;P&gt;Hi,  I am looking at this too many hours again.  In Microsoft SQL via vb6 front end.&lt;BR /&gt;
&lt;/P&gt;
&lt;P&gt;I use:
db.Execute "if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[BuildFileAllOthersCDC]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)" &amp;amp; _
          "drop table [dbo].[BuildFileAllOthersCDC]"&lt;/P&gt;
&lt;P&gt;In Sybase with the same VB program.
I am trying to use:
myConnTM.Execute "if exists (select * from sysobjects where name=" 'mytable' " = 1) drop table 'mytable'"&lt;/P&gt;
&lt;P&gt;I have tried all froms of this, all I can think of, does the "if exists" work with SYBASE SQL?  I get an error, "Syntax error near if line one"
Will trade gray hairs for suggestions... smile&lt;/P&gt;
&lt;P&gt;George&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2012 17:22:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaq-p/13827505</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-05-14T17:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sybase db.execute if exist in vb6 &amp; SQL</title>
      <link>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827506#M4858349</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;myConnTM.Execute "if exists (select 1 from sysobjects where name= 'mytable' ) drop table mytable"&lt;/P&gt;
&lt;P&gt;Changes&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Fixed the name predicate which read " 'mytable' ". Should be 'mytable' without additional quotes.&lt;/LI&gt;
&lt;LI&gt;Removed the = 1.&lt;/LI&gt;
&lt;LI&gt;Changed the select list to SELECT 1 from SELECT *.&lt;/LI&gt;
&lt;LI&gt;Changed DROP statement to DROP TABLE mytable.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;BTW
Is this a SQL Anywhere question or an Adaptive Server Enterprise question? The syntax changes were tested in SQL Anywhere.&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2012 19:50:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827506#M4858349</guid>
      <dc:creator>chris_keating</dc:creator>
      <dc:date>2012-05-14T19:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Sybase db.execute if exist in vb6 &amp; SQL</title>
      <link>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827508#M4858351</link>
      <description>&lt;P&gt;SQLAnywhere.
Here is what I am getting to work:
myConnATT.Execute "if exists (select 1 from autotiretech..sysobjects where name= 'EMAIL_LIST' ) drop table EMAIL_LIST"
myConnATT.Execute "create table EMAIL_LIST (""Name"" Char)"
Notice the double quotes on the column name.  I can not get single quote to work for some reason.  Can you point me to the values of the '1' after the select statement.  I am new to SQLA so some of this takes me a few more hours then it should... smile.&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2012 23:24:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827508#M4858351</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-05-14T23:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Sybase db.execute if exist in vb6 &amp; SQL</title>
      <link>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827507#M4858350</link>
      <description>&lt;P&gt;What version of SQL Anywhere are you using?&lt;/P&gt;
&lt;P&gt;Version 11.0.1 and above support the &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbreference/drop-table-statement.html"&gt;"DROP TABLE IF EXISTS MyTable" syntax&lt;/A&gt;, by this omitting the need to check beforehand if the table already exists.&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2012 03:19:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827507#M4858350</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-05-15T03:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: Sybase db.execute if exist in vb6 &amp; SQL</title>
      <link>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827509#M4858352</link>
      <description>&lt;P&gt;As to the "if exists (...)" vs. " = 1" tests:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;EXISTS&lt;/STRONG&gt;&lt;BR /&gt;
&lt;/P&gt;
&lt;P&gt;The existence test (EXISTS) checks whether a subquery produces any rows of query results. If the subquery produces one or more rows of results, the EXISTS test returns TRUE. Otherwise, it returns FALSE. &lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's what you're about here: You simply want to check if there is at least one row for that table in the system catalog.&lt;/P&gt;
&lt;P&gt;The "= 1" would be useful if you would count the number of rows, i.e. for something like:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;if (select count(*) from sysobjects where name= 'mytable') = 1 then ... end if;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 15 May 2012 03:27:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827509#M4858352</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-05-15T03:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sybase db.execute if exist in vb6 &amp; SQL</title>
      <link>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827510#M4858353</link>
      <description>&lt;P&gt;BTW: SQL Anywhere has &lt;STRONG&gt;two different SQL dialects&lt;/STRONG&gt; for SQL batches, stored procedures and the like: &lt;STRONG&gt;Watcom SQL and Transact SQL&lt;/STRONG&gt; (T-SQL), the latter is mostly similar to the dialects of ASE and MS SQL Server. The doc tell the &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbusage/ug-sql-compat.html"&gt;differences en detail here&lt;/A&gt; - you just should be aware that one SQL batch should be written in one dialect...&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2012 03:34:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827510#M4858353</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2012-05-15T03:34:59Z</dc:date>
    </item>
    <item>
      <title>Re: Sybase db.execute if exist in vb6 &amp; SQL</title>
      <link>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827511#M4858354</link>
      <description>&lt;P&gt;I don't have VB6 installed on my machine at this time but the statement&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;myConnATT&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;Execute&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"create table EMAIL_LIST (""Name"" Char)"&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;appears to be written correctly. You can also use [NAME] to delimit the identifier name. This assumes that your quoted_identifier database option is set to ON. See &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbadmin/quoted-identifier-option.html"&gt;http://dcx.sybase.com/index.html#1201/en/dbadmin/quoted-identifier-option.html&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Or you could write it as&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;myConnATT&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;Execute&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"create table EMAIL_LIST ("&lt;/SPAN&gt; &lt;SPAN class="o"&gt;&amp;amp;&lt;/SPAN&gt; &lt;SPAN class="n"&gt;char&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;34&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="o"&gt;&amp;amp;&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"Name &amp;amp; char(34) &amp;amp;"&lt;/SPAN&gt; &lt;SPAN class="n"&gt;Char&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;SPAN class="err"&gt;"&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;For troubleshooting statements, I build the value into a string variable and display it in a messagebox or an edit box to see what the value actually looks like.&lt;/P&gt;
&lt;P&gt;For example (unchecked syntax but I think this is mostly correct)&lt;/P&gt;
&lt;P&gt;dim stmt as String
   stmt = "create table EMAIL_LIST (""Name"" Char)"
   msgbox stmt
   tb.Text = stmt&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2012 09:10:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827511#M4858354</guid>
      <dc:creator>chris_keating</dc:creator>
      <dc:date>2012-05-15T09:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Sybase db.execute if exist in vb6 &amp; SQL</title>
      <link>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827512#M4858355</link>
      <description>&lt;P&gt;Thanks, I have this working/understood.  I need  to do it across two DB's, both SQLAnywhere.  Will :  Location work on SQLA 10?&lt;/P&gt;
&lt;P&gt;INSERT INTO iq_table 
LOCATION 'ase_servername.ase_dbname' 
{ SELECT col1, col2, col3,...
FROM owner.ase_table } &lt;/P&gt;
&lt;P&gt;What I am doing is working with a DB that has read only, I need to grab data, put it together and then export it for the customer.  So I have a second DB, just a little problem getting the data from on to the other.... smile&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2012 11:27:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827512#M4858355</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-05-15T11:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sybase db.execute if exist in vb6 &amp; SQL</title>
      <link>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827513#M4858356</link>
      <description>&lt;P&gt;This will not work in a pure SA environment. In SA, you need to implement remote server and proxy tables to achieve this.&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2012 11:49:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sybase-db-execute-if-exist-in-vb6-sql/qaa-p/13827513#M4858356</guid>
      <dc:creator>chris_keating</dc:creator>
      <dc:date>2012-05-15T11:49:06Z</dc:date>
    </item>
  </channel>
</rss>

