Solved

SQL: Drop temp table if exists is returning error

Posted on 2014-10-08
1
670 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to solve "recursive" database tables 2 59
Sorting a SQL script 5 41
Search Text in Views 2 28
Convert DateTime format in SQL query 10 23
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
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.

751 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