Skip to content
Advertisement

Keyword IF not expected

I have the following inline SQL code, running on an AS400. The IF comes up as unexpected but I don’t understand why. What I’m trying to do is to build a stored procedure to update, or insert, a table row. The code shown below is inline to ensure my logic is correct.

I’ve tried a number of different approaches including IF EXISTS, CASE, SET @COUNT = SELECT COUNT(*). I continue to run into odd errors.

In the code shown below, I fail when I hit the IF statement.

Advertisement

Answer

You should show the error you get…

with the following:

I get [SQL0199] Keyword BEGIN not expected. Valid tokens: THEN.

This passes a syntax check, note THEN and END IF instead of BEGIN also, COMMIT instead of COMMIT TRANSACTION

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement