title: simple insert procedure, check for duplicate
body: <p>I am creating a program that is going to insert data into a table which is pretty simple</p>
  
  <p>But my issue is I want my insert statement to make sure that it isnt inserting duplicate data</p>
  
  <p>I want to somehow check the table the data is going into to make sure that there isnt a row with the same indivualid and categoryid and value </p>
  
  <p>So if I am inserting      </p>
  
  <pre><code>indivualid = 1
  categorid = 1
  value = 1
  </code></pre>
  
  <p>and in my table there is a row with</p>
  
  <pre><code>indivualid = 1
  categorid = 1
  value = 2 
  </code></pre>
  
  <p>my data would still be inserted </p>
  
  <p>but if there was a row with</p>
  
  <pre><code>indivualid = 1
  categorid = 1
  value = 1
  </code></pre>
  
  <p>then it wouldnt</p>
  
  <p>I tried this</p>
  
  <pre><code>IF @value = 'Y'
  OR @value = 'A'
  OR @value = 'P'
  AND NOT EXISTS
    (SELECT categoryid,
            individualid
     FROM ualhistory
     WHERE categoryid = @cat
       AND individualid = @id)
  INSERT INTO individuory(categoryid, individualid, value, ts)
  VALUES (@cat,
          @id,
          @yesorno,
          getdate())
  </code></pre>
  
  <p>but it still inserts duplicates.</p>