title: SQL INSERT but avoid duplicates
body: <p>I want to do some quick inserts but avoid duplicates into a Table.
  For argument's sake lets call it MarketPrices, I've been experimenting with two ways of doing it but not sure how to benchmark which will be faster.</p>
  
  <pre><code>INSERT INTO MarketPrices (SecurityCode, BuyPrice, SellPrice, IsMarketOpen)
  SELECT @SecurityCode, @BuyPrice,  @SellPrice, @IsMarketOpen
  EXCEPT
  SELECT SecurityCode, BuyPrice, SellPrice, j.bool as IsActive FROM MarketPrices
  CROSS JOIN (SELECT 0 as bool UNION SELECT 1 as bool ) as j
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>DECLARE @MktId int
  SET @MktId = (SELECT SecurityId FROM MarketPrices 
                where SecurityCode = @SecurityCode 
                and BuyPrice=@BuyPrice 
                and SellPrice = @SellPrice)
  
  IF (@MktId is NULL)  
  BEGIN
      INSERT INTO MarketPrices (SecurityCode, BuyPrice, SellPrice, IsMarketOpen)
      VALUES
      (@SecurityCode,@BuyPrice, @SellPrice, @IsMarketOpen)
  END
  </code></pre>
  
  <p>Assume that <code>@whatever</code> is an input parameter in the stored procedure.</p>
  
  <p>I want to be able to insert a new record for every SecurityCode when the BuyPrice or SellPrice or both are different from every other previous occurance.  I don't care about IsMarketOpen.</p>
  
  <p>Is there anything glaringly stupid about either of the above approaches? Is one faster than the other? </p>