IF @someVariable = 0
BEGIN
SELECT *
INTO #TempTable
FROM MyTable
WHERE Category="Something"
END
ELSE
BEGIN
SELECT *
INTO #TempTable
FROM MyTable
WHERE Category="SomethingElse"
END
DROP TABLE #TempTable
Comes up with “There is already an object named ‘#TempTable’ in the database. Is there a way around this?
This will work, but depending on what else you may need the code to do, might not be the best solution; but in your example code it solves the problem.
Alternatively: