I need to order a varchar column in the following way: 100, 110, 120, [...] 1490, 1495, 1495.1, 1495.2, 1495.3, etc.
With help from another question, I created this function:
CREATE FUNCTION isNumeric(value VARCHAR(1024))
RETURNS TINYINT(1) DETERMINISTIC
RETURN value REGEXP '^(-|\\+)?([0-9]+\\.[0-9]*|[0-9]*\\.[0-9]+|[0-9]+)$';
And then added this to my query:
ORDER BY isNumeric(ItemCode) DESC, CASE WHEN isNumeric(ItemCode) = 1 THEN CAST(ItemCode as UNSIGNED) ELSE NULL END, ItemCode
It worked great. Unfortunately, when I tried this on the live server, I wasn't able to create the function. "Column count of mysql.proc is wrong. Expected 20, found 16. Created with MySQL 50067, now running 50147. Please use mysql_upgrade to fix this error." My boss says we can't run an update in case it breaks something, so I was hoping someone could help me achieve the same thing without a function. Thanks!