Why does SQL Server thinks a Temp Table already exists when it doesn't?

后端 未结 4 898
挽巷
挽巷 2020-12-20 15:54

Background: There\'s a stored procedure which does \"stuff\" with a temp table of a given name. The procedure is generic in that it inspects the schema of the temp table and

4条回答
  •  余生分开走
    2020-12-20 16:49

    since i dont have sql 2008, i cannot test it. however as far as i know, this is a parser issue explicitly with temp tables. the same would work fine with normal tables

    to sort this out, just split your code with logical GO statements

    ideally: check for existence of temp tables before you create your temp tables, drop them if they exist, fire a go, do the creation of temp tables again, fire a go, then any post processing, fire a go, finally drop them again and fire the last go


    you might also want to try and use the table variable instead of temp tables if above does not solve it for you

提交回复
热议问题