开发者

Forgot to Drop Temp Table, now I can't get Rid of It

开发者 https://www.devze.com 2023-01-31 17:16 出处:网络
I wrote a stored procedure and created a temp table #TempHitRatioTable.I forgot to put the drop table statement in my procedure and now no matter what I do I can\'t get rid of the temporary table and

I wrote a stored procedure and created a temp table #TempHitRatioTable. I forgot to put the drop table statement in my procedure and now no matter what I do I can't get rid of the temporary table and can't re-execute the procedure. I have tried completely disconnecting from the server and reconnecting, but it is still there. I have tried the following statements:

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

and I also tried:

IF EXISTS(SELECT * FROM sys.tables WHERE name LIKE '#TempHitRatioT开发者_运维知识库able%')
DROP TABLE #TempHitRatioTable

IF EXISTS(SELECT 1 FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'#TempHitRatioTable') AND type = (N'U')) DROP TABLE #TempHitRatioTable

But I still can't get rid of that table. My stored procedure is no longer running, nor is the crystal report I tried to run it on, but nothing seems to work. Please help.


I figured out what was happening. I had put the create table at the bottom of the cursor inside of it, so each time the cursor iterated throught to add a new record the table was already created. I moved the create table to the top of the stored procedure, before I created the cursor, added the statement: IF OBJECT_ID('tempdb..#TempHitRatioTable') IS NOT NULL DROP TABLE #TempHitRatioTable at the top of the procedure, then I added the drop table statement to the end of the procedure and all is well. I can run it as many times as I want and get all my results back not just one record. Silly me :-)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号