When I use the following in a script, it does not DROP the table. I would have to highlight this line and execute it by itself and when running the entire script, it works. Is it because I am missing a semicolon? I have tried to replicate the error but sometimes the script runs entirely and other times, it errors out and I would have to manually drop the TEMP table.
IF OBJECT_ID('tempDb..#TempTable') IS NOT NULL DROP TABLE #TempTable