title: SQL Delete Where Not In
body: <p>I have a relation mapping table like this:</p>
  
  <p>attributeid bigint<br>
  productid bigint</p>
  
  <p>To clean relations that are not used any more, I want to delete all recors where productid = x and attributeid not in (@includedIds), like the following example:</p>
  
  <pre><code>@attributetypeid bigint, 
  @productid bigint,
  @includedids varchar(MAX)  
  
  
  DELETE FROM reltable 
  WHERE productid = @productid AND 
  attributetypeid = @attributetypeid AND 
  attributeid NOT IN (@includedids);
  </code></pre>
  
  <p>When running the SQL with the includedids param containing more than 1 id - like this: 25,26 - I get a SqlException saying:</p>
  
  <p>Error converting data type varchar to bigint.</p>
  
  <p>And that is of course due to the , in that varchar(max) param...</p>
  
  <p>How should I construct my delete statement to make it work?</p>