Skip to Content
Former Member
Jul 19, 2013 at 12:26 PM

if exists not evaluated correctly


Sybase version

Adaptive Server Enterprise/15.0.3/EBF 17690 ESD#1.1 RELSE/P/Solaris AMD64/OS 5.10/ase1503/2681/64-bit/FBO/Thu Aug 20 15:37:40 2009

Good afternoon,

I have a question regarding my SQL code below

if exists (select name from tempdb..sysobjects where name = 'SSt_stats_purge')

print 'table exists'


create table tempdb..SSt_stats_purge(scan_date datetime, value int)

The first time I execute it, it creates my table SSt_stats_purge.

The second time I execute, I expect it won't create it but I have an error saying

Msg 2714, Level 16, State 1

Server 'HP249SRV1', Line 16

There is already an object named 'SSt_stats_purge' in the database.

What's wrong with my code?

Thanks all for your advices