Solved

Stored proc not getting created because temp table already exists.

Posted on 2013-10-25
3
394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 66

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

630 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