title: IF EXISTS with SQL Server 2008
body: <p>I have a table order in which there are 3 columns</p>
  
  <pre><code>  BookCode  Quantity  Billno
    --------------------------    
     Ed001        2      A1
     Ed002        3      A1
     Ed003        1      A1
     py001        5      A2
     ed001        1      A2
     ed005        2      A2
     ed003        4      A2
  </code></pre>
  
  <p>Now I want to show my result to user as</p>
  
  <p>table <strong>Result</strong></p>
  
  <pre><code>   BookCode   A1     A2
     ----------------------    
     Ed001      2      1
     Ed002      3      0
     Ed003      1      4
     py001      0      5
     ed005      0      1
  </code></pre>
  
  <p>Result is my temporary table, I alter it and add column according to <code>Billno</code></p>
  
  <p>this works fine</p>
  
  <p>Now I select <code>BookCode</code> and <code>Quantity</code> from table <code>Order</code> and insert it into result</p>
  
  <p>What I want that if there is already a <code>bookcode</code> exist then just update <strong>result</strong> table otherwise insert a new row with that bookcode.</p>
  
  <p>What should I do for that?</p>