title: How to check if record exists in another table and if not then add
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/8312058/insert-statement-that-checks-for-duplicate-before-insert">Insert statement that checks for duplicate before insert</a>  </p>
  </blockquote>
  
  
  
  <p>I'd like to check if a building id exists in the issue log table using the foreign key b_id. And if it does not exist then i would like to add it to the issue log table. 
  I have the code below but this only checks to see which buildings are not in the issue log table...how can i do the insert? Thanks a lot. I'm using SQL Server 2008.</p>
  
  <pre><code>select b.b_id from building 
  where not exists(select b.b_id from issue_log as l where b._id = l.b_id)
  </code></pre>