title: Stored Procedure with Optional DateTime Parameters in SQL Server
body: <p>How to write this <code>select</code> query in SQL Server when the <code>datetime</code> parameters (<code>@StartDate</code> &amp; <code>@EndDate</code>) are optional in this stored procedure?</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[prSearchEmployees]
  (
      @Id INT = NULL
      ,@FullName VARCHAR(20) = NULL
      ,@Age INT = NULL
      ,@StartDate = NULL
      ,@EndDate = NULL
  )
  AS
  BEGIN
     SELECT * 
     FROM Employee 
     WHERE Id = ISNULL(@Id, Id) 
       AND FullName LIKE ISNULL(@FullName + '%', FullName)
       AND Age = ISNULL(@Age, Age)
  END
  </code></pre>