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 8879343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:55:47+00:00 2026-06-14T19:55:47+00:00

My table data like id LedgerName 1 105 AAA 2 102 sss 3 GGGG

  • 0

My table data like

id LedgerName
1  "105 AAA"
2  "102 sss"
3  "GGGG"
4  "107 BBB"
5  "BBBB"
6  "101 TTT"

i want sorting the Ledger like

6  "101 TTT"
2  "102 sss"
1  "105 AAA"
4  "107 BBB"
5  "BBBB"
3  "GGGG"

Normal Order by is not working.
i used split function to split for number based sorting in order by ..
how to fix this issue

  • 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-14T19:55:48+00:00Added an answer on June 14, 2026 at 7:55 pm

    With the data you have provided a regular order by on LedgerName is doing what you want.
    Below is version that deals with data that is a bit more complicated.

    SQL Fiddle

    MS SQL Server 2008 Schema Setup:

    create table YourTable
    (
      id int,
      LedgerName varchar(20)
    )
    
    insert into YourTable values
    (1,  '105 AAA'  ),
    (2,  '1020 sss' ),
    (3,  ' '        ),
    (4,  null       ),
    (5,  '0'        ),
    (6,  '999 sss'  ),
    (7,  '9999 sss' ),
    (8,  'GGGG'     ),
    (9,  '107 BBB'  ),
    (10, 'BBBB'     ),
    (11, '101 TTT'  )
    

    Query 1:

    select id,
           LedgerName
    from YourTable
    order by case when patindex('%[^0-9]%', isnull(LedgerName, '')+' ') = 1 then 1 else 0 end,
             cast(left(LedgerName, patindex('%[^0-9]%', LedgerName+' ')-1) as int),
             LedgerName
    

    Results:

    | ID | LEDGERNAME |
    -------------------
    |  5 |          0 |
    | 11 |    101 TTT |
    |  1 |    105 AAA |
    |  9 |    107 BBB |
    |  6 |    999 sss |
    |  2 |   1020 sss |
    |  7 |   9999 sss |
    |  4 |     (null) |
    |  3 |            |
    | 10 |       BBBB |
    |  8 |       GGGG |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My table data is looks like: SessionRefere http://www.google.com/url?sa=t&rct=j&q=aaa bbb&source=web&cd=1&cad=rja&sqi=2&ved=0CB4QFjAA&url=http://www.abc.com/&ei=QFR0UM-JKIrQrQfsuoG4CQ&usg=AFQjCNExYcKkcvobBbktLGNksptf1giQRw ------------------------------------------------- http://www.google.com/reader/view/?hl=es&tab=Xq&at=RTknd_lBUUnvNqan2641EA ---------------------------------------------------- http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=5&cad=rja&ved=0CEgQFjAE&url=http://www.abc.com/ppp.aspx&ei=dmd0UOO9AYnY4QS1sYGwBw&usg=AFQjCNGIFcJUUSVpl_ZiZoSWDP2LkIagtw It's
My table have data structure like this cate_id task_id date_start date_end other 34 14
I have a table that has data like below(sorted by date) COL_A | COL_B
I have a data.table object like this one library(data.table) a <- structure(list(PERMNO = c(10006L,
I have a table like this: Application,Program,UsedObject It can have data like this: A,P1,ZZ
I have a table (call it table myTable). It has the data like this:
I'm a bit confused on this. I have a data table structured like this:
I would like to add a data table to bottom of a (line) chart
data table contain column named as Fld_primary. this column contain value like 0.00 it
I have a table called Addim and the data looks like: TName Idate Number

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.