Question : HELP --> Select max(varchar) from table;  ERGENT

I have a field called order_no to keep track the order number.
Previously set order_no to varchar in database. In order to get new order_no when creating new order, i do a select max(order_no)+1 from ocf table;

Problem now is the order_no reach 10000, and when i do a select max(order_no) from ocf; the query result 9999.

I do an update ocf set order_no=10001 where order_no=9999;

THEN do a select max(order_no) again, it return 9998
(10001 < 9998 ????!!!)

I know the max() is to work for Int only, but without changing the field type from varchar to integer, any solution for this?

Appreciate it very much. THANKS!

Answer : HELP --> Select max(varchar) from table;  ERGENT

see here:
http://www.mysql.com/doc/en/Cast_Functions.html#IDX1308

select max(  CAST( order_no as UNSIGNED ) + 1 from ocf table

CHeers
Random Solutions  
 
programming4us programming4us