title: handling null parameter in where clause stored procedures
body: <p>Is there a better way in sql to select all if a variable is null and if it's not null apply the where filter?</p>
  
  <p>Example:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[GetAllOrders]  
      @OrderNo varchar(50) =null
      AS
  
      IF @OrderNo IS NULL
          BEGIN   
              SELECT CustomerNo,Name,Surname,etc...
              FROM Customers 
          END
      ELSE
          BEGIN       
              SELECT CustomerNo,Name,Surname,etc...
              FROM Customers 
              WHERE OrderNo = @OrderNo
          END
  </code></pre>
  
  <p>tried as follows but does not do it
  WHERE (OrderNo IS NULL OR OrderNo = @OrderNo)</p>
  
  <p>many thanks</p>