Solved

Stored proc not getting created because temp table already exists.

Posted on 2013-10-25
3
381 Views
Last Modified: 2013-10-30
Using Sql Server 2012

I am using the following code where ever I am creating a temp table #wt3 in my stored proc code. But when I hit execute to create this SP I get the error mentioned below, at the second instance of creating this temp table:

IF (OBJECT_ID('tempdb..#wt3')) IS NOT NULL
			DROP TABLE #wt3	
SET ANSI_WARNINGS OFF
 SELECT TOP 0 * INTO #wt3 FROM db_template.dbo.DimTime

Open in new window


Error:
Msg 2714, Level 16, State 1, Procedure rollup_scores, Line 1463
There is already an object named '#wt3' in the database.

What am I missing?

Thank you.
0
Comment
Question by:patd1
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 39600280
Hmm... works on my SQL 2012 box every time.  Just for kicks and giggles, remove the extra parentheses marks, and add the begin and end, and see if that makes a difference.
IF OBJECT_ID('tempdb..#wt3') IS NOT NULL
   begin
   DROP TABLE #wt3	
   end

CREATE TABLE #wt3 (id int) 
INSERT INTO #wt3 (id) VALUES (7)
SELECT * FROM #wt3

Open in new window

Any chance this error is occuring somewhere else (Line 1463 is a long ways down)?
Show us the entire SQL code.

Also, I wonder if there is a SET statement somewhere that controls this behavior.
0
 

Assisted Solution

by:patd1
patd1 earned 0 total points
ID: 39600489
It wasn't working with Create SP, but worked with Alter sP.
What I did was named my temp table as #wt3_p while i was creating the SP.
Then went back in and removed the _p, so now I am doing an Atler SP with temp table named as #wt3 and it worked.

I guess there is some bug in create SP.
0
 

Author Closing Comment

by:patd1
ID: 39611023
more research.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now