Right This query is not working if the query is running in another DB session
and also this syntax is wrong
select * from sysobjects where name = '#testvm%'
if the query is like
select * from sysobjects where name like '#testvm%'
and the session is in tempdb then it will work otherwise it will be like bellow
select * from tempdb..sysobjects where name like '#testvm%'
Yousaf Khan