#Temp Table Problem

DECLARE @TxtPtr binary(16), @applicantid integer, @Data varchar(8000), @Offset integer
SET              NOCOUNT ON CREATE TABLE #Temp(applicantid integer, RTF text) DECLARE YourCursor CURSOR FOR
                          SELECT     applicantid
                           FROM         gradrec_coverletter_t

I have been using the following code successfully for a year.

Now I keep getting the error There is already an object named '#temp' in the database.

Is there something in the code I need to change?

I have looked in the tempdb database on the server, under temporary tables and theres about 7 instances of #temp table. I tried changing the temp tablename to #letters but still got the same error only with #letters in it.

Is there anyway I can resolve the error?


FROM         YourCursor
INTO            @applicantid WHILE @@FETCH_STATUS = 0 BEGIN INSERT #Temp(applicantid, RTF)
VALUES     (@applicantid, '')
                          SELECT     @TxtPtr = TEXTPTR(RTF), @OffSet = 0
                           FROM         #Temp
                           WHERE     applicantid = @applicantid WHILE @OffSet IS NOT NULL BEGIN
                                                      SELECT     @Data = CAST(CAST(SUBSTRING(document_im, @Offset + 1, 8000) AS varbinary(8000)) AS varchar(8000))
                                                       FROM         gradrec_coverletter_t
                                                       WHERE     applicantid = @applicantid IF Len(@Data) > 0 BEGIN UPDATETEXT #Temp.RTF @TxtPtr @Offset NULL @Data
SET              @OffSet = @OffSet + 8000 END ELSE BEGIN
SET              @OffSet = NULL END END FETCH NEXT
FROM         YourCursor
INTO            @applicantid END CLOSE YourCursor DEALLOCATE YourCursor
                          SELECT     applicantid, RTF
                           FROM         #Temp
Mark WilsonBI DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
IF OBJECT_ID('tempdb..#temp') IS NOT NULL
    drop table #temp

-- All your code goes here

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.