IF object_id('tempdb..#TableName') IS NOT NULL DROP TABLE #TableName
I think this will not work as we know sql server store temp table name with adding some extra character.
if exists(select 1 from tempdb.sys.tables where name like '#TableName%')
DROP TABLE #TableName