I'm trying to write an SQL statement that will check whether a table exists and, if so, dropping it in System i.
I assumed it would be a simple IF EXISTS
statement but I'm having trouble with it and unsure how to proceed.
The statement in full:
IF EXISTS (SELECT TABLE_NAME FROM <<DatabaseName>>.VIEWS
WHERE TABLE_NAME = 'TABLE')
DROP VIEW <<DatabaseName>>.TABLE
GO
It comes back with the error
Keyword IF not expected
I'm a complete beginner with System i but I've read about procedures can get round this?
You can use an IF statement inside a stored procedure, so you could accomplish this with something like:
You could then call this proc passing in the table name, schema, and column definition:
I haven't actually tested this, but this should give you a basic idea of what you need to do.