Check for existence of a # table

the easiest way of checking for the existence of a # table is to check it’s object id

if exists(select 1 from tempdb.dbo.sysobjects where object_id = object_id(‘tempdb.dbo.#worktable’))

drop table #worktable

Also applies to sql 2005 and 2008