Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have an error while trying to run a simple SQL statement!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Well, the problem is: I run the statement below:
if not exists (select * from sysobjects where name = 'temptable')
BEGIN
create table temptable(name int)
END
ELSE
BEGIN
SELECT * FROM temptable
END
when I run it the first time, there are no problems, but the second time I run it, I receive the error:
Msg 2714, Level 16, State 1
There is already an object named 'temptable' in the database.
Is there a solution?
 
Nothing is wrong with your statemnt.
It seems like you need to reboot your server. It happened with us also, and after rebooting everything was OK.
Did we find a new bug in SQL server?
 
You are creating a table called temptable so the next time you run you are trying to create a table that you have already created.
You need to drop the table when the querry finishes.

Ged Jones

Top man
 
This looks like Sybase (but I'm sure other DB's are the same) ... the problem is (from the manual)

When a create table or create view command occurs within an if...else block, Adaptive Server creates the schema for the table or view before determining whether the condition is true. This may lead to errors if the table or view already exists.

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top