title: How to choose how to fill #temptable in sql?
body: <p>Okay, I've got what is probably a very easy question for you Sql gurus out there...</p>
  
  <p>Given a boolean of some kind, T, I want to populate a temp table with data set A, if T is true, or data set B, if T is false.  I thought this would be how to do it:</p>
  
  <pre><code>DECLARE @foo INT
  SET @foo = null
  
  IF (@foo is null)
      BEGIN
          SELECT 'foo was null' INTO #TempTable
      END
  ELSE
      BEGIN
          SELECT 'foo not null' INTO #TempTable
      END
  </code></pre>
  
  <p>But this doesn't work.  I get an error that reads "There is already an object named '#TempTable' in the database."</p>
  
  <p>Apparently Sql is trying to create the table in each case, before it evaluates the condition...?  That seems odd to me, but okay...  But what's the proper way to do something like this?</p>
  
  <p><strong>Edit: I'm in Sql Server, but I suspect that this is a more universal issue...but if I'm wrong, please let me know.</strong></p>