|
Home > Archive > SQL Anywhere for Linux > April 2005 > SQL syntax?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Ken Panacy 2005-04-05, 8:03 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
| |
| Greg Fenton 2005-04-05, 8:03 pm |
| Ken Panacy wrote:
>
> 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/
| |
| Chris Gruber 2005-04-05, 8:03 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 in message news:417ffc5b.587d.1681692777@sybase.com...
> 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
| |
| David Fishburn 2005-04-05, 8:03 pm |
| "Chris Gruber" <chris.gruber@ianywhere.com> wrote in
news:41a508af$2@foru
ms-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
[url]http://ianywhere.codexchange.sybase.com/servlets/ ProjectDocumentList[
/url]
|
|
|
|
|