To simplify the problem: I have a database table with one column. In this column there can be stored any text by users (so we have dynamic data). Now lets say I store the
example data:
[a1, a2, a3, a20, a21].
When I now select the data from the table, I want it to be sorted like this:
a1, a2, a3, a20, a21
and not like this:
a1, a2, a20, a21, a3
Is there a way without writing a complex algorithm (because I am using Access2007 and want to bind the table or any query to an element in a form), but use only sql.
Please notice:
If the users would only insert numbers, the column type could simply be changed to number. Then it would be sorted the right way. But I have to handle also letters and special characters.
What you are asking for has several steps involved each of them with its own difficulties, meanly because you want to do it using SQL. Your phrase
without writing a complex algorithmon the question and the commentEverything is possibleare incompatible.Everything is possibleadds lot of complexity to what you are trying to do, mainly because sql was not ment to do what you are trying to do here.What @Remou is talking about in the comment is that instead of all values on a column you should have those values on different rows. Like for example:
From here you can start doing some ordering.
One first step you could do is to split the string in several rows, save on a temp table and from here you have something to work with. You can use the following snippet to split a string on rows: