cancel
Showing results for 
Search instead for 
Did you mean: 

if exists not evaluated correctly

Former Member
0 Kudos

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'

else

    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

Former Member
0 Kudos

Thank you Marc for this explanation.

Great to receive valuable feedback on this site.

Simon

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos
Former Member
0 Kudos

Thank you Christine,

I didn't read the whole page, my bad.

Simon