I am from non database background. I have created a table with one of the field data type TEXT.
dataF TEXT
INSERTION:
Have inserted three records with the values :
'842-2-4'
'842-2-5'
'842-2-6'
SELECTION:
Tring to get the records based on date now.
... where dateF between '842-2-4' and '842-2-10'
It fails.
Whereas,
... where dateF between '842-2-4' and '842-2-8'
retrieves all the 3 records.
What am i doing wrong ? Why the first statment fails ?
Kindly suggest.
When comparing strings, the values are compared left to right…
As one string is shorter that the other, you are kind of comparing this…
Well, nothing is
>= '842-2-4'AND<= '842-2-1'.'842-2-1'comes before'842-2-4'.And, so,
'842-2-10'comes before'842-2-4'too.Just as
'Squiggled'comes before'Squiggly''xxx-y-az'comes before'xxx-y-z'To compare as you desire, make sure all your dates are padded with
0‘s.But that will only work after you have padded out the values in your table too.
EDIT:
Also, note that this assumes that your format is
YYYY-MM-DD. As a string is compared left to right, you must have the highest magnitude values to the left.(This means that you can’t use
YYYY-DD-MMand still have native string comparisons behave as you would want them.)