title: Temporary Table in if statement
body: <pre><code>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
  </code></pre>
  
  <p>Comes up with "There is already an object named '#TempTable' in the database. Is there a way around this?</p>