title: SQL Server Insert if not exists
body: <p>I want to insert data into my table, but insert only data that doesn't already exist in my database.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[EmailsRecebidosInsert]
    (@_DE nvarchar(50),
     @_ASSUNTO nvarchar(50),
     @_DATA nvarchar(30) )
  AS
  BEGIN
     INSERT INTO EmailsRecebidos (De, Assunto, Data)
     VALUES (@_DE, @_ASSUNTO, @_DATA)
     WHERE NOT EXISTS ( SELECT * FROM EmailsRecebidos 
                     WHERE De = @_DE
                     AND Assunto = @_ASSUNTO
                     AND Data = @_DATA);
  END
  </code></pre>
  
  <p>And the error is: </p>
  
  <blockquote>
    <p>Msg 156, Level 15, State 1, Procedure EmailsRecebidosInsert, Line 11<br>
    Incorrect syntax near the keyword 'WHERE'.</p>
  </blockquote>