title: SQL ignore part of WHERE if parameter is null
body: <p>I have a stored procedure that fetches info from a table based on 4 parameters.</p>
  
  <p>I want to get values based on the parameters, but if a parameter is NULL then that parameter isn't checked. So if all 4 parameters is null I would show the entire table.</p>
  
  <p>This is my SP (as you can see, this only works for 1 parameter atm):</p>
  
  <pre><code>CREATE PROCEDURE myProcedure
      @Param1 nvarchar(50),
      @Param2 nvarchar(50),
      @Param3 nvarchar(50),
      @Param4 nvarchar(50)
  AS
  BEGIN
      IF(@Param1 IS NULL)
          BEGIN
              SELECT Id, col1, col2, col3, col4 FROM myTable
          END
      ELSE
          BEGIN
              SELECT Id, col1, col2, col3, col4 FROM myTable WHERE col1 LIKE @Param1+'%'
          END
  END
  </code></pre>
  
  <p>Is there some way to do this <em>without</em> having a <code>IF</code> for every possible combination (15 IFs)?</p>