0

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.

2 Answers 2

6

You can use cast or convert to convert the field type:

... ORDER BY CAST(receiptno AS INTEGER) ASC

Edit sorry, fixed syntax

Sign up to request clarification or add additional context in comments.

1 Comment

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
1

So, change the type of this column

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.