as
declare @exec varchar(8000)
set @exec='use tempdb
if exists(select * from sysobjects
where id=object_id(''tempdb..'+@tablename+'''))
print '''+@tablename+'表存在''
else
print '''+@tablename+'表不存在'''
exec (@exec)
--测试
create table #test(id int,name varchar(20))
temp '#test'
go
temp '#test1'
-----------
#test表存在
#test1表不存在