title: Using IF statement to check if temporary table has rows in a stored procedure
body: <p>How can I use an IF statement in my stored procedure to check if my temporary table has rows?</p>
  
  <p>I want to check if #TempDataTable has rows then I would do either of the two statements, insert or update depending on the output. </p>
  
  <p>I did the following:</p>
  
  <pre><code>BEGIN
      SELECT * 
      INTO #TempDataTable 
      FROM
          (SELECT * 
           FROM BranchNameTable BT 
           LEFT JOIN BranchLocationActivate BLA ON BT.loc_id = BLA.loc_id 
           WHERE BT.Branchloc = 1;) as Q
  
      if(//TempDataTable has 0 rows)
  
         INSERT INTO BranchLocationActivate 
         VALUES(//my values)
  
      ELSE
  
         UPDATE BranchLocationActivate 
         SET //My values where //my values
  END
  </code></pre>
  
  <p>How do I put it after my select statement in my procedure??</p>