dbTalk Databases Forums  

SQL syntax?

sybase.public.sqlanywhere.linux sybase.public.sqlanywhere.linux


Discuss SQL syntax? in the sybase.public.sqlanywhere.linux forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ken Panacy
 
Posts: n/a

Default SQL syntax? - 10-27-2004 , 02:51 PM






Hello,

I'm trying to do a simple If Exists... table update on a
"Sybase Adaptive Server Anywhere e-Business Anywhere" db on
a Linux server. I'm getting a syntax error but I don't know
enough about Sybase to see what's wrong here.

Here's my code.
IF NOT EXISTS(SELECT * FROM LP_DIV WHERE DIV_NUM='070388')
THEN BEGIN INSERT INTO LP_DIV (DIV_NUM, NAME, CREATE_DTM)
VALUES ('070388', '070388', NOW()); INSERT INTO LP_DIV_GRP
(GRP_CD, DIV_NUM) VALUES ('ALL','070388');END
IF NOT EXISTS(SELECT * FROM LP_DIV WHERE DIV_NUM='070416')
THEN BEGIN INSERT INTO LP_DIV (DIV_NUM, NAME, CREATE_DTM)
VALUES ('070416', '070416', NOW()); INSERT INTO LP_DIV_GRP
(GRP_CD, DIV_NUM) VALUES ('ALL','070416');END

Is it okay that the lines have several commands and are
separated by semi-colons?

Thanks.
Ken

Reply With Quote
  #2  
Old   
Greg Fenton
 
Posts: n/a

Default Re: SQL syntax? - 10-28-2004 , 09:30 AM






Ken Panacy wrote:
Quote:
I'm trying to do a simple If Exists... table update on a
Answered in the ianywhere.public.general newsgroup.

Please do not cross-post.

greg.fenton
--
Greg Fenton
Consultant, Solution Services, iAnywhere Solutions
--------
Visit the iAnywhere Solutions Developer Community
Whitepapers, TechDocs, Downloads
http://www.ianywhere.com/developer/


Reply With Quote
  #3  
Old   
Chris Gruber
 
Posts: n/a

Default Re: SQL syntax? - 11-24-2004 , 04:18 PM



Ken,

I am assuming that you are using IF EXISTS in a batch type script.

Here is an example of such a script.

if not exists (select * from "DBA"."foo" where "col1"=1) then
insert into "DBA"."foo" ("col1","col2") values (1,2)
end if
go

Otherwise you may consider the following syntax.

insert into "DBA"."foo" ("col1","col2") values (1,2) on existing update.

Chris Gruber
iAnywhere Solutions

<Ken Panacy> wrote

Quote:
Hello,

I'm trying to do a simple If Exists... table update on a
"Sybase Adaptive Server Anywhere e-Business Anywhere" db on
a Linux server. I'm getting a syntax error but I don't know
enough about Sybase to see what's wrong here.

Here's my code.
IF NOT EXISTS(SELECT * FROM LP_DIV WHERE DIV_NUM='070388')
THEN BEGIN INSERT INTO LP_DIV (DIV_NUM, NAME, CREATE_DTM)
VALUES ('070388', '070388', NOW()); INSERT INTO LP_DIV_GRP
(GRP_CD, DIV_NUM) VALUES ('ALL','070388');END
IF NOT EXISTS(SELECT * FROM LP_DIV WHERE DIV_NUM='070416')
THEN BEGIN INSERT INTO LP_DIV (DIV_NUM, NAME, CREATE_DTM)
VALUES ('070416', '070416', NOW()); INSERT INTO LP_DIV_GRP
(GRP_CD, DIV_NUM) VALUES ('ALL','070416');END

Is it okay that the lines have several commands and are
separated by semi-colons?

Thanks.
Ken



Reply With Quote
  #4  
Old   
David Fishburn
 
Posts: n/a

Default Re: SQL syntax? - 11-25-2004 , 07:11 AM



"Chris Gruber" <chris.gruber (AT) ianywhere (DOT) com> wrote in
news:41a508af$2@forums-1-dub of sybase.public.sqlanywhere.linux:

CG> Otherwise you may consider the following syntax.
CG>
CG> insert into "DBA"."foo" ("col1","col2") values (1,2) on existing
CG> update.

I think that should be:
CG> insert into "DBA"."foo" ("col1","col2")
CG> on existing update
CG> values (1,2);

--
David Fishburn
Certified ASA Developer Version 8
iAnywhere Solutions - Sybase
Professional Services
Please only post to the newsgroup
Please ALWAYS include version and MORE importantly BUILD number with
EACH post (dbeng9 -v).

EBFs and Maintenance Releases
http://downloads.sybase.com/swx/sdmain.stm

Developer Community / Whitepapers
http://www.ianywhere.com/developer

CaseXpress - to report bugs
http://casexpress.sybase.com

CodeXchange - Free samples
http://ianywhere.codexchange.sybase....ctDocumentList


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.