title: Search by date in sql server
body: <p>Below is my .aspx code</p>
  
  <pre><code>&lt;asp:SqlDataSource ID="sdsVisitors" runat="server" ConnectionString="&lt;%$ ConnectionStrings:ApplicationServices %&gt;"
     SelectCommand="Visitors_Select_All" SelectCommandType="StoredProcedure"&gt;
      &lt;SelectParameters&gt;
            &lt;asp:ControlParameter ControlID="txtVisitorID" DbType="Int32" Name="VisitorID" PropertyName="Text"  DefaultValue="0" /&gt;
  
            &lt;asp:ControlParameter ControlID="txtName" Name="FirstName" PropertyName="Text" ConvertEmptyStringToNull="true"
                                  DefaultValue="%" /&gt;
            &lt;asp:ControlParameter ControlID="ddlFloor" Name="Floor" PropertyName="SelectedValue"
                                  ConvertEmptyStringToNull="true" DefaultValue="%" /&gt;
            &lt;asp:ControlParameter ControlID="ddlLocation" Name="Location" PropertyName="SelectedValue"
                                  ConvertEmptyStringToNull="true" DefaultValue="%" /&gt;
            &lt;asp:ControlParameter ControlID="ddlEmployee" DbType="Int32" Name="EmployeeID" PropertyName="SelectedValue"
                                  DefaultValue="0" /&gt;
            &lt;asp:ControlParameter ControlID="txtMobile" Name="Mobile" PropertyName="Text"
                                  ConvertEmptyStringToNull="true" DefaultValue="%" /&gt;
            &lt;asp:ControlParameter ControlID="txtFromDate" Name="FromDate" PropertyName="Text"
                                ConvertEmptyStringToNull="true" DefaultValue="%" /&gt;
      &lt;/SelectParameters&gt;
   &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>and my store procedure is</p>
  
  <pre><code>  ALTER PROCEDURE [dbo].[Visitors_Select_All]
  @VisitorID INT = 0 ,
  @FirstName VARCHAR(30) = '' ,
  @LastName VARCHAR(30) = '' ,
  @City VARCHAR(30) = '' ,
  @Floor VARCHAR(50) = '' ,
  @Location VARCHAR(50) = '' ,
  @Mobile VARCHAR(13) = '' ,
  @EmployeeID INT = 0 ,
  @FromDate VARCHAR(100) = ''
  AS 
     BEGIN
  
      SELECT  V.[VisitorID] ,
              V.[FirstName] ,
              V.[MiddleName] ,
              V.[LastName] ,
              V.[Gender] ,
              V.[Age] ,
              V.[DetailWithMaterials] ,
              V.[City] ,
              V.[State] ,
              V.[PinCode] ,
              V.[Phone] ,
              V.[Mobile] ,
              V.[Date] ,
              V.Location ,
              E.Email
      FROM    [dbo].[Visitors] AS V
              LEFT OUTER JOIN [dbo].[Employees] AS E ON V.EmployeeID = E.EmployeeID
      WHERE   V.FirstName LIKE @FirstName + '%'
              AND V.LastName LIKE @LastName + '%'
              AND V.City LIKE @City + '%'
              AND V.[Floor] LIKE @Floor + '%'
              AND V.Location LIKE @Location + '%'
              AND V.Mobile LIKE @Mobile + '%'
              AND ( ( @VisitorID &lt;&gt; 0
                      AND V.VisitorID = @VisitorID
                    )
                    OR ( @VisitorID = 0 )
                  )
              AND ( ( @EmployeeID &lt;&gt; 0
                      AND V.EmployeeID = @EmployeeID
                    )
                    OR ( @EmployeeID = 0 )
                  )
              AND ( ( CONVERT(VARCHAR(20), V.Date, 103) = @FromDate )
                    OR ( @FromDate = '' )
                  )
      ORDER BY Date DESC
  
  END
  </code></pre>
  
  <p>Now what i want is if i do not pass any parameter value then all record should be return and when i pass <code>@FromDate</code> then record of that date should be return. But this is not working now. If i remove <code>@FromDate</code> condition then it's working. Any help would be appreciated. Thanks. </p>