Jim Youmans
asked on
DB2 IF variable IS NULL THEN GOTO exit
DB2 10.5 on Windows.
I am working on a procedure that captures a variable from a select statement and if it is null then it needs to exit. This is the code.
When I run this I get this error.
ERROR [42601] [IBM][DB2/NT64] SQL0104N An unexpected token "v_OLD_ID" was found following "IF ". Expected tokens may include: "JOIN <joined_table>".
Not sure what I am doing wrong. Any suggestions would be greatly appreciated.
Thanks!
Jim
I am working on a procedure that captures a variable from a select statement and if it is null then it needs to exit. This is the code.
CREATE VARIABLE v_OLD_ID VARCHAR(15);
SET v_OLD_ID = (
SELECT a
FROM db2.table1
WHERE KEY = 12345);
SELECT v_OLD_ID from SYSIBM.SYSDUMMY1; -- shows null
IF v_OLD_ID IS NULL THEN GOTO exit;
-- do other stuff
exit:
DROP VARIABLE v_OLD_ID;
When I run this I get this error.
ERROR [42601] [IBM][DB2/NT64] SQL0104N An unexpected token "v_OLD_ID" was found following "IF ". Expected tokens may include: "JOIN <joined_table>".
Not sure what I am doing wrong. Any suggestions would be greatly appreciated.
Thanks!
Jim
ASKER
I am using TOAD for DB2. According to them I can do this.
TOAD IF THEN ELSE
How do you do this type of thing?
Jim
TOAD IF THEN ELSE
How do you do this type of thing?
Jim
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
Where are you executing this? Most client environments don't let you run things (like this) that you can in SSMS.
Kent