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.

If I run the following statement:

//create a watcom function
CREATE OR REPLACE FUNCTION "DBA"."TEST1" (@val INT)
RETURNS INTEGER
BEGIN

    IF (@val = 1) THEN
        SET @val = 2;
    ENDIF;

    RETURN @Val;
END;
//create a t-sql function
CREATE OR REPLACE FUNCTION "DBA"."TEST2" (@val INT)
RETURNS INTEGER
AS
BEGIN

    IF @val = 1 BEGIN
        SET @val = 2;
    END
    RETURN @Val;
END;

It runs fine, no errors.

But if I run this:

//create a t-sql function
CREATE OR REPLACE FUNCTION "DBA"."TEST1" (@val INT)
RETURNS INTEGER
AS
BEGIN

    IF (@val = 1) BEGIN
        SET @val = 2;
    END

    RETURN @Val;
END;
//create a t-sql function
CREATE OR REPLACE FUNCTION "DBA"."TEST2" (@val INT)
RETURNS INTEGER
AS
BEGIN

    IF @val = 1 BEGIN
        SET @val = 2;
    END
    RETURN @Val;
END;

It throws:

Could not execute statement.
Syntax error near 'FUNCTION' on line 14 (Transact-SQL)
SQLCODE=-131, ODBC 3 State="42000"
Line 15

Line 14 is where the second function declaration starts, so it's like it's reading off the end of the first function because of the BEGIN/END statement in the IF clause.

Am I writing bad code and/or is there something I'm missing? I write most of my procedure/functions in t-sql and use IF/ELSE quite a bit. If run the CREATE FUNCTION statements individually they don't throw errors.

Any help would be appreciated.

SQL Anywhere 17 17.0.10.5963

asked 30 Apr '21, 08:19

samrae's gravatar image

samrae
23191022
accept rate: 50%

closed 30 Apr '21, 08:22

The question has been closed for the following reason "Duplicate Question" by samrae 30 Apr '21, 08:22

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:

×246
×29
×28
×5
×1

question asked: 30 Apr '21, 08:19

question was seen: 736 times

last updated: 30 Apr '21, 08:22