Simple - don't store dates in
varchar
columns. Use
one of the many date/time types[
^] available to you instead.
Using a
varchar
column, you need 20 bytes to store a single date. With
datetime
, you only need 8 bytes; with
datetime2
, between 6 and 8.
Using a
varchar
column, there is no validation of the stored data. Before long, you'll find dates in different formats; ambiguous dates
(is "01/02/03" supposed to be 1st Feb 2003, 2nd Jan 2003, or 3rd Feb 2001?); and random junk that you can't even convert to a date by hand.
If you
can't change the column type for some bizarre reason, you'll need to convert the column in your
WHERE
clause as well:
WHERE
SAMPLE_TYPE = 'SampleSchedule'
AND
Convert(datetime, SCHEDULE_NEXT_DATE, 104) BETWEEN @DateFrom AND @DateTo