I have the field receiptno
, which is a varchar holding a numeric value, and want to sort this. Sorting as a string gives me the wrong ordering. I'd like to try sorting it as an integer. Is there anyway to converting to integer in the order by clause so I can sort by integer in the query itself.
views:
130answers:
2
+3
A:
You can use cast
or convert
to convert the field type:
... ORDER BY CAST(receiptno AS INTEGER) ASC
Edit sorry, fixed syntax
adam
2010-04-15 11:33:59
Thanks for your answer, In mysql cast function integer have problem, so i used signed. now working. ORDER BY CAST(receiptno AS SIGNED) ASC - working properly
Karthik
2010-04-15 11:47:32
...and ruin any index use. excellent
Col. Shrapnel
2010-04-15 11:54:09
Oh ok nice. Thanks col
Karthik
2010-04-15 12:16:33