SQL SERVER2008里面sql语句删除临时表失败

来源:百度知道 编辑:UC知道 时间:2024/05/28 10:09:45
我首先 select * into #temp_table
from ShopEmpDayWorkMst
where BrandCode='1001' and ShopCode='1001'

select * from #temp_table
然后执行
if (select OBJECT_ID('tmep..#temp_table')) is not null drop table #temp_table
但是再执行select * from #temp_table 结果里面依然有数据,并且执行
select * into #temp_table
from ShopEmpDayWorkMst
where BrandCode='1001' and ShopCode='1001'
的时候还会提示说对象‘#temp_table’已经存在
为什么会这样?我哪里写错了吗?

if (select OBJECT_ID('tmepdb..#temp_table')) is not null drop table #temp_table
这里写错了,是'temp..#temp_table'数据库名称写错了Tempdb被你写成了 tmep
所有临时表都是在tempdb数据库的

if object_id('Tempdb..#temp_table') is not null
drop table #temp_table

--or
if not object_id('Tempdb..#temp_table') is null
drop table #temp_table

if (select OBJECT_ID('tmep..#temp_table')) is not null drop table #temp_table
这句
你改下

把if(select ……) is not null 删掉 直接drop table #temp_table