title: SQL Server Stored Procedure Check if Record Exists Before Insert
body: <p>I am doing a check to see if a record exists before inserting it into a table (and this method seems to work on other stored procedures I am already using) but for this particular stored procedure it is not inserting anything even though the table is empty, why not?</p>
  
  <pre><code>CREATE PROCEDURE spInsertMovieHasTrailer
      @movieID int,
      @name varchar(50)
  AS
  BEGIN
      SELECT @name = name, @movieID = movieID
      FROM MovieHasTrailer
      WHERE name = @name and movieID = @movieID
  
      IF @name IS NULL and @movieID IS NULL
      BEGIN
      INSERT INTO MovieHasTrailer
      (
          movieID,
          name
      )
      Values (
          @movieID,
          @name
      )
      END
  END
  </code></pre>
  
  <p>Executing like this:</p>
  
  <pre><code>execute spInsertMovieHasTrailer 1, 'Test'
  </code></pre>