This entire code makes no sense.
Your ASP code will run *ONE TIME* and the result will be nothing but a number.
So you will end up doing the SQL query
(or whatever the number turns out to be).
SELECT * FROM Company ORDER BY 37
When you use a number in ORDER BY, it is specifying the *FIELD NUMBER* from the SELECT!!!
In other words, if you did
That would be the same thing as doing
SELECT a, b, c, d, e, f FROM Company ORDER BY 5
ORDER BY e, the 5th field in the SELECT.
You can *NOT* call an external function in the middle of a SQL query.
You will need to rewrite your function to be a MySQL function, *NOT* an ASP function.
So throw out that code and start over.