Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7675927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:04:52+00:00 2026-05-31T17:04:52+00:00

Given: code inside a stored proc: select bleh into #tblTemp from FunctionThatReturnsTable(‘some’,’params’) — do

  • 0

Given:

code inside a stored proc:

select bleh
  into #tblTemp
  from FunctionThatReturnsTable('some','params')

-- do some stuff

drop table #tblTemp

-- Error on this command:
-- 'There is already an object named '#tblTemp' in the database.'
select bleh
  into #tblTemp
  from FunctionThatReturnsTable('some','other params')

Problem:

I can’t recreate this temp table. My work around is to use #tmpTable1, #tmpTable2, #tempTable3 etc. Is there a way I can get around this? It would be nice just use one temp table each time.

If not, what is the reason for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:04:53+00:00Added an answer on May 31, 2026 at 5:04 pm

    As my comment reflected, I’m going to suggest that the answer is that you use a different #temp table name for each object that you create. It’s kind of like saying to the doctor, “it hurts when I do this.” His likely response is going to be, “stop doing that!”

    The reason this is a problem is that SQL Server’s parser attempts to parse the entire batch in one shot. It can clearly see that you are trying to create the same #temp table multiple times, but ignores the DROP command in between (I can’t tell you exactly why that is, as I don’t have access to the source code). This is the same reason you can’t do this:

    IF (1=1)
      CREATE TABLE #foo(i INT);
    ELSE
      CREATE TABLE #foo(i VARCHAR(32));
    

    The parser sees the two identical names, but can’t really follow the IF/ELSE logic.

    In addition to avoiding the problems multiple identically-named #temp tables causes the parser, another benefit to using unique names is that they can be re-used if you don’t explicitly drop them. This will lighten the load on tempdb in terms of metadata / locking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the code from here : class lazy_init { mutable std::once_flag flag; mutable std::unique_ptr<expensive_data>
im stuck on calling stored procedures inside a SELECT CASE on a Trigger, it
Appreciate some insight given the following code: <script type=text/javascript> $(document).ready(function() { var soapEnv =
Given this code: var arrayStrings = new string[1000]; Parallel.ForEach<string>(arrayStrings, someString => { DoSomething(someString); });
Given the code below, how would you create/implement SR.h so that it produces the
Given the code below ... Net::HTTP.start('localhost', 4000) do |http| # # usual stuff omitted
Given the code below, how do I compare a List of objects's values with
Given this code: List<string> things = new List<string>(); foreach (string thing in things) {
In the code given below, I need to position the userid box in the
In the code given below, I am trying to modify it in such a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.