|
Over the years, I have noticed
several people asking for a way to check for the existence of a
table along the likes of the CHKFILE function. I wrote a stored
procedure that will check for a table and return a 1 or a 0 if it
exists or not. Since it returns a value, it can be used in an IF
statement (IF (CALL CHKTABLE('tablename')) = 1 THEN...). I'll
paste the code below. It is not terribly original, but someone
may find it useful. If you use it, you will need to set vctocheck
TEXT 128 as the only argument (table names in 9.5 x64 max out at
128 characters, if you are using another version adjust as
necessary), and the return value as an integer.
-- CHKTABLE Stored Procedure -- Jason Kramer -- 07-05-2012 -- This RMD file is used by the CHKTABLE stored procedure (SP). It requires -- one parameter, the table name to check, and returns a 0 (not found) or a 1 -- (found). -- Required parameter - vctocheck TEXT - the name to check. -- Return value - 0 or 1: -- 0 - Table does not exist. -- 1 - Table exists. SET VAR vctretval INTEGER = NULL SELECT COUNT sys_table_name INTO vctretval FROM sys_tables WHERE sys_table_name = .vctocheck RETURN .vctretval Jason Kramer University Archives and Records Management 002 Pearson Hall (302) 831 - 3127 (voice) (302) 831 - 6903 (fax) |

