Hi frnd:
Basically it is unable to find temporary table #TmpTable
First of all i would like to know where you are creating
#TmpTable table.
One another thing missing in the below line:
SET @SQLQuery = 'select * into TmpTable From Staff'
It should be like this :
SET @SQLQuery = 'select * into #TmpTable From Staff'
My suggestion is instead of using this code:
if exists (select * from tempdb.dbo.sysobjects o where o.xtype in ('U')
and o.id = object_id(N'tempdb..#TmpTable'))
DROP TABLE #TmpTable;
Modify the code like this :
if exists (select * from tempdb.dbo.sysobjects o where o.xtype in ('U')
and o.id = object_id(N'tempdb..#TmpTable'))
Begin
DROP TABLE #TmpTable;
Create Table #TmpTable(
Id int
)
End