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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:23:53+00:00 2026-05-29T07:23:53+00:00

I have a column named Code that is varchar(3). It contains numbers and strings

  • 0

I have a column named Code that is varchar(3).

It contains numbers and strings as well. For example: ' 1', '234', 'Xxx', '9 ','Aa ' etc.

Is there way -just like in MS EXCEL- ORDER anything that looks like a number, as a number?

So that output for the given example above will be:

1. 1 
2. 234 
3. 9 
4. Aa 
5. Xxx
  • 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-05-29T07:23:54+00:00Added an answer on May 29, 2026 at 7:23 am
    ORDER BY CASE WHEN ISNUMERIC(YourField) = 1 THEN CONVERT(INT, YourField) - 500 ELSE ASCII(LOWER(YourField)) END
    

    If the field can be converted to a number it is sorted by number otherwise it uses ASCII coding to sort. I have used “- 500” just so there is no cross over in the sort, and to ensure numbers are sorted ahead of text.


    ADDENDUM:

    Brian Arsuaga has posted a more robust solution to this which I actually prefer, but since this has already been marked as the answer I am adding his solution to this for the benefit of anyone reading this in the future.

    ORDER BY 
            ISNUMERIC(YourField) DESC, 
            CASE WHEN ISNUMERIC(YourField) = 1 THEN CONVERT(INT, YourField) ELSE 0 END,
            YourField
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, I have a table, and there is a column named 'Tags'. I
I have ten or more(i don't know) tables that have a column named foo
I have a self referencing table named categories that has a parentcategoryid column that
I have this sp. I just found out that M.MDS_FILE column, contains a file
I have column named summary (tinytext, utf8_turkish_ci). I know it can store 255 byte
I have a books model with a date type column named publish_date. On my
To dynamically fill DropDown controls on my HTML Form, I have written code that
I have a sproc that returns a single line and column with a text,
We have a table in our system that stores resource key/value pairs. There are
I have a column in my database named Created which is a datetime and

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.