Solved

Stored proc not getting created because temp table already exists.

Posted on 2013-10-25
3
383 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MSSQL: Replace text (typo) 7 34
TSQL previous 5 26
Rename SQL Instance/SQL Developer Edition 2012 2 12
What namespace do I need to import? 2 14
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

863 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

19 Experts available now in Live!

Get 1:1 Help Now