1

I get an syntax error on line 7 - "BEGIN" for while -

 BEGIN
        IF EXISTS(SELECT 1 from table1)
        THEN
            IF EXISTS(SELECT 1 from table2)
            THEN
            WHILE EXISTS(SELECT 1 FROM table3)
            BEGIN
                BEGIN TRANSACTION;

                COMMIT TRANSACTION;
            END
            END IF;
        END IF;
    END

Any suggestions or pointers?

Vishal
  • 12,133
  • 17
  • 82
  • 128
  • 1
    Have you tried using T-SQL `IF`, instead of Watcom `IF - THEN` syntax? http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.sqlanywhere.12.0.1/dbreference/if-tsql-statement.html – Mike Gardner Oct 21 '13 at 15:55
  • @MichaelGardner It did work, but unfortunately not yet working in the bigger picture. I'm guessing if we use both syntaxes mixed I guess it may cause issues? – Vishal Oct 21 '13 at 16:24
  • not sure about whether that causes issues or not. – Mike Gardner Oct 21 '13 at 16:34

1 Answers1

1

The problem was as @Michael pointed out, there are two different type of dialects - T-SQL and WATCOM-SQL, I had to rewrite while loop in Watcom-SQL syntax to be compatible with rest of Watcom-sql syntax -

BEGIN
        IF EXISTS(SELECT 1 from table1)
        THEN
            IF EXISTS(SELECT 1 from table2)
            THEN
            WHILE EXISTS(SELECT 1 FROM table3) LOOP
            BEGIN
                BEGIN TRANSACTION;

                COMMIT TRANSACTION;
            END LOOP;
            END IF;
        END IF;
    END
Community
  • 1
  • 1
Vishal
  • 12,133
  • 17
  • 82
  • 128