January 22, 2003 at 6:36 pm
IF EXISTS( SELECT 1 FROM sysobjects WHERE name = 'table_name' AND type = 'U' ) ...
Type 'U' is for User-defined table.
Alternatively, you could use the SCHEMA object.
Edited by - mromm on 01/22/2003 6:37:52 PM
January 22, 2003 at 6:41 pm
You can also do
IF OBJECT_ID('tblname') IS NOT NULL
but the IF EXISTS method is MS standard way.
January 23, 2003 at 4:29 pm
that seems to do the trick with the table test; but what about an ELSE statement? how does SQL know where the THEN part of the IF ends?
January 23, 2003 at 6:12 pm
IF <condition>
<code block>
ELSE
<another code block>
where <code block> is either one statement or block as below:
BEGIN
<some code>
END
Viewing 4 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply