Solved

SQL: Drop temp table if exists is returning error

Posted on 2014-10-08
1
677 Views
Last Modified: 2014-10-08
Error: There is already an object named '#tmpAnticipatedReleaseDate' in the database.

Before creating a temp table, I am checking if one already exists, but am receiving an error message, and don't know why.

IF OBJECT_ID('tempdb..#tmpAnticipatedRelease') IS NOT NULL                         
DROP TABLE #tmpAnticipatedReleaseDate 
GO  

-- Reference table containing anticipated release dates for all disbursements               
CREATE TABLE #tmpAnticipatedReleaseDate                
(                
DisbursementId INT NOT NULL,                
AnticipatedReleaseDate DATETIME               
)                
CREATE CLUSTERED INDEX cx ON #tmpAnticipatedReleaseDate(DisbursementId, AnticipatedReleaseDate)     


;WITH 
cteInstallmentHoldDueDate AS (
SELECT 
	InSc.InstallmentScheduleId, Insc.DueDate, 
	Di.DisbursementId, Di.Amount, Di.ReleaseDate, DiH.DisbursementHoldId, DiH.DisbursementHoldTypeId, DiH.HoldValue
FROM 
	Disbursement Di
	JOIN DisbursementHold DiH ON DiH.DisbursementId = Di.DisbursementId AND DiH.DisbursementHoldTypeId = 1
	JOIN InstallmentSchedule InSc ON InSc.CustomerAccountId = Di.PartyId AND InSc.InstallmentNumber = DiH.HoldValue
)

INSERT INTO #tmpAnticipatedReleaseDate (DisbursementId, AnticipatedReleaseDate)

SELECT Di.DisbursementId, Di.ReleaseDate
FROM 
	Disbursement Di

Open in new window

0
Comment
Question by:pzozulka
[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
1 Comment
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 40369361
Object name is slightly off in the IF:

IF OBJECT_ID('tempdb..#tmpAnticipatedReleaseDate') IS NOT NULL                        
    DROP TABLE #tmpAnticipatedReleaseDate
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

631 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