Solved

Stored proc not getting created because temp table already exists.

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Stored Proc - Rewrite 42 62
SQL Log size 3 20
Finding gaps or missing dates in a date range using TSQL 3 28
Display SQL 2008 last modified/update Database 11 21
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

821 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