title: How to filter records on condition if filter value is NULL in SQL Server?
body: <p>I want to filter records in SQL Server on two conditions. I am writing a stored procedure for that. </p>
  
  <p>This is my query</p>
  
  <pre><code>// Parameters 
  @carNo AS INT
  @carEngineNo AS INT = null    // this is optional
  
  Select * 
  From CarLog
  //Some Joins
  Where 
      CarLog.car_no = carNo 
      // here I want condition, I tried this but there is some syntax error
      And CASE
              When @carEngineNo IS NOT NULL THEN CarLog.engine_no= carEngineNo 
              WHEN @carEngineNo IS NULL  THEN CarLog.engine_no = CarLog.engine_no
              END
  </code></pre>
  
  <p>How can I do this?</p>