Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8563019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:51:47+00:00 2026-06-11T16:51:47+00:00

To simplify the problem: I have a database table with one column. In this

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:51:49+00:00Added an answer on June 11, 2026 at 4:51 pm

    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 algorithm on the question and the comment Everything is possible are incompatible. Everything is possible adds 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.

    • First validate the format of the string: yes, it can be done, but SQL is a query language, better do to any kind of formatting outside if possible
    • Then split it taking into account all the different possibilities that can appear: again, SQL is not meant for this, you can do it, but there are many different cases on your data
    • Finally order the values: and again, ordering and return a single string. Ordering is ment to be done on a set, not in a chain of values, but can be done of course

    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:

    id    value
    1      a1
    2      a41
    3      s2
    4      a52
    5      a1b99ccc
    

    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:

    DECLARE @str NVARCHAR(100)= 'T,23,3434,332SB,1-1KD', @separator VARCHAR(1)= ','
    DECLARE @SplitedList  TABLE (code NVARCHAR(30))
    
    DECLARE @XMLList XML
    SET @XMLList=CAST('<i>'+REPLACE(@str, @separator,'</i><i>')+'</i>' AS XML)
    
    INSERT INTO @SplitedList
    SELECT x.i.value('(./text())[1]','varchar(100)')
    FROM @XMLList.nodes('i') x(i)
    
    SELECT * FROM @SplitedList
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'll try to simplify the problem as much as I can. I have an
I have a table created in a migration (only to simplify the problem) that
I think i can simplify the problem domain. Basically i have set the preference
I'll simplify the problem as much as possible: I have an oracle table: row_priority,
I've created a sample project to simplify my problem. I have this simple handler:
To simplify the problem down for the question, I have a listings table and
to simplify this let take that table: table1 ------------- id unique primary int myVal1
Sorry for the title, I really couldn't think of how to simplify this problem.
I have a table my_table with these fields: id_a, id_b. So this table basically
I have two tables in my database: Company table (ID, CompanyName, CompanyUsername, CompanyPassword) Employee

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.