Conceptually, I would like to sort data of a single column of variant type, similar to how this is done in Excel:

[![enter image description here](https://i.stack.imgur.com/cYWcj.png)](https://i.stack.imgur.com/cYWcj.png)

Here we can see that Numbers are sorted before Strings before Booleans before Errors. So, I would like to have a function that works like this in SQL:

```
SELECT * FROM table ORDER BY
  CASE WHEN type='number' THEN 0 WHEN type='string' THEN 1 /* ... */ END,
  SortFunction(variantData)

```

Here is what I'd like to accomplish:

* The `SortFunction` needs to return a value of a single data type, for example, a string, or a number, or a binary type.
* I am fine limiting the length of a text field in the function, if that is necessary (for example, if we have a string that is 10,000 characters, just limiting it to the first 100 characters).

Any programming language is fine, I'm more concerned just about a technique to accomplish this Excel-like sorting.

For a numeric field, we can keep it as-is, for a date/time-related field we can do a unix timestamp, but how would we do it for a string or binary data type?