Deleting Temporary Tables in MSSQL
Sometimes there is a need to delete a temporarily created table during a procedure, which may or may not exist. Simply writing, for example, drop table #myTempTable is not enough, because if the table does not exist, the query will not execute and will return an error. The example below shows how to correctly delete temporary tables in such cases: