I have a search form with min and max fields. It queries a MySQL table.
The field ‘List Price’ is varchar and contains values with commas such as 200,000 or 34,150.
I can’t retieve the correct records…
( List Price BETWEEN ‘100000’ AND ‘101000’ ) I get records that are 101900 – higher than the max.
( List Price BETWEEN ‘100,000’ AND ‘101,000’ ) I get records that are >= min and <= max
( List Price <= ‘101,000’ ) I get records that are like 100,000 but also 1,280,000 and 1,300,000
( List Price >= ‘300,000’ ) I get records that are like 399,900 but also 70,000
Is it because the field value is char instead of int? Can the comma be stripped from the field in the mysql select? ( List Price >= ‘300,000’ <- somehow remove the comma from the number, so the select would read ‘List Price’ >= 300000 )
Thanks…
You should convert that varchar field to a decimal type, alowing proper numeric comparisons. You could force it to be numeric-ish by stripping out the commas and doing a CONVERT(), e.g.