title: T-SQL IF statement explanation
body: <p>I'm really puzzled by this one!! I'm sure it's simple but really can't figure it out!!</p>
  
  <pre><code>DECLARE @jobid INT = 100
     IF (@JobID &gt;= 0)
   BEGIN 
  SELECT * into #tmp FROM Persons 
   end
      ELSE
   BEGIN
  SELECT * into #tmp FROM Persons1 
   end
  </code></pre>
  
  <p>It gives an error that the <code>#tmp</code> table already exists! Why it would validate both statements !</p>
  
  <p>Of course my original query is huge and doing more, but that's a sample to illustrate my error.</p>
  
  <p>Can anybody explain it please?</p>
  
  <p>The <code>#tmp</code> table is not there, even when you try to drop it or change the name, still the engine validates both statements!</p>
  
  <p>I'm using 2008 R2.</p>
  
  <p>Thanks
  Jason</p>