date stored in varchar column

  • I am unable to retrieve data based on the where clause which refers to the date(stored in a varchar) column.

    SELECT count(*)

    FROM table1 where colls like '%ABC%'

    and table1.unit=@unit

    and

    date

    between

    @startdate

    and

    @enddate

    GO

    It reurns 0 rows.

    Thanks

  • Which is why you should store dates in a datetime column.

    try "and convert(datetime, date) between" ...

    of course, this will completely prevent the use of any supporting indexes on that field.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply