You must Sign In to post a response.
  • Category: SQL Server

    Search operation on a table with multiple values

    We perform search operation on a table based on multiple values. We have a column "CreatedDate" - smalldatetime, we insert including time Ex: 10/24/2017 2:09:00 PM.
    But while searching we pass values from date, to date as "10/24/2017", "10/30/2017" respectively using between operator, but its not returning the result set.

    Query :

    select * from TestTable where (Location='Hyderabad') AND (EmpId='101') AND
    (CreatedDate between @FromDate and @ToDate)

    Thanks in advance
  • #769473

    You need to cast the CreatedDate in same datatype as you are passing in parameters to search for.

    Please try this:

    select * from TestTable where (Location='Hyderabad') AND (EmpId='101') AND
    (cast(CreatedDate as Date) between @FromDate and @ToDate)


    Anjali Bansal

    ~Give your best and lead the world

  • Sign In to post your comments