Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

Why I can't write an IF STATEMENT / TRIGGER EVENT STATEMENT within a WHILE LOOP?

My Script looks like this:

while (1=1)

begin

trigger event MYEVENT;

waitfor delay 50;

load into table TABLE1 from 'C:\Temp\2020.CSV' DELIMITED BY ';' quote '"' skip 1

if exists (select * from TABLE1 except select * from TABLE2) then

  insert into exporterrorlogs (exportstatus) values ('NOK');

else

  insert into exporterrorlogs (exportstatus) values ('OK');

end if;

end

The same applies if I try to use LOOP statement instead of WHILE END.

Which alternative do I have in order to write a conditional statement within an endless loop?

Any Ideas? Thanks in advance

asked 15 May '20, 07:10

Baron's gravatar image

Baron
2.1k138150178
accept rate: 48%

edited 15 May '20, 08:16

Volker%20Barth's gravatar image

Volker Barth
40.2k361550822

3 downvotes? Why?

(16 May '20, 06:17) Volker Barth

WHILE you are mixing Watcom-SQL and Transact-SQL syntax LOOP
   errors may show up;
END LOOP;
permanent link

answered 15 May '20, 07:17

Volker%20Barth's gravatar image

Volker Barth
40.2k361550822
accept rate: 34%

converted 15 May '20, 13:17

But is there a way to realize this bulk of watcom-sql statements in an endless loop without doing this mixing?

(15 May '20, 07:27) Baron
Replies hidden

Have you tried to use the Watcom-SQL WHILE/LOOP/END LOOP syntax? - For an overview, see here.

Aside: You have not told what the error is, so I don't know whether this is due to dialects - but mixing both dialects surely is error-prone and sometimes leads to rather meaningless resp. irritating error messages.

(15 May '20, 08:16) Volker Barth

LOL! ...very funny :)

(15 May '20, 08:22) Breck Carter

The error is syntax error

(15 May '20, 18:35) Baron

but how can I distinguish between those 2 dialects (watcom / Transact)?

Why I cant find the "Watcom-SQL WHILE/LOOP/END Loop Syntax" in the PDF documentation of SQL Anywhere Server SQL Anywhere - SQL Reference?

(15 May '20, 18:52) Baron
1

See http://dcx.sap.com/index.html#sqla170/en/html/3bec29c76c5f1014a91fa4cd3ffedef7.html*loio3bec29c76c5f1014a91fa4cd3ffedef7

The issue is that Watcom dialect, WHILE is a clause of the LOOP statement.

If a statement is TSQL, it is identified as such. See http://dcx.sap.com/index.html#sqla170/en/html/817adec96ce21014abeedc732b220dbe.html

In the case of the WHILE statement that you used, the statement is titled as WHILE statement [T-SQL].

(15 May '20, 22:35) Chris Keating
1

Just to add: Watcom-SQL is the name of SQL Anywhere's native SQL dialect, so unless otherwise noted, all documented SQL statements belong to this dialect.

In contrast, SQL Anywhere also supports a subset of the Transact-SQL dialect (T-SQL), as used by ASE and MS SQL Server. Those statements are generally marked as such, see Chris's comment.

And while (pun intended) you can use both dialects in the same database connection, you cannot do so within one SQL code block, such as a stored procedure.

(16 May '20, 06:44) Volker Barth
showing 2 of 7 show all flat view
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×36

question asked: 15 May '20, 07:10

question was seen: 1,177 times

last updated: 16 May '20, 06:46