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

The Archive Base Latest Questions

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

Hi all please look at my table below Name ———- Banaskantha – 66-DV Banaskantha

  • 0

Hi all please look at my table below

Name
----------
Banaskantha - 66-DV
Banaskantha - 66-MM
Banaskantha-Dv
Banaskantha-MM
Bharuch - 77-RP
Bharuch-RP
hg-SR

but I want this table in below order

Name
-------------
Banaskantha-Dv
Banaskantha-MM
Banaskantha - 66-DV
Banaskantha - 66-MM
Bharuch-RP
Bharuch - 77-RP
hg-SR

How can I do that ?

  • 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-11T17:01:48+00:00Added an answer on June 11, 2026 at 5:01 pm

    Try the following sql statement:

     SELECT name, 
           case isnumeric(SUBSTRING(name, LEN(name)-4,2))
         when 1 then
                 left(name, len(name)-8) + 'z' + RIGHT(name, 2) + '-' + SUBSTRING(name, LEN(name)-4,2)
             else name 
       end as sortby
    FROM [your table name]
    order by sortby
    

    The query adds a field for sorting purposes. The value of that field depends if the name field has numeric value in it. If yes, it converts it to perfix (i.e. ‘Banaskantha’) + ‘z’ (so it will be below any instance of the prefix without the suffix), suffix (i.e. ‘DV’) + the numeric value. If it has no numeric value then it keeps the original value.

    I made several assumptions:

    1. The numeric value is always starts 5 characters from the end
    2. There is always space between the prefix (i.e. Banaskantha) and the ‘-‘ and between the ‘-‘ and the numeric value when there is numeric value in field value
    3. There is no space between the prefix and suffix when the field value has no numeric value in it.

    If one of the assumptions is not correct, rewrite the SQL statement accordingly.

    Let me say that the problem starts because there is no consistency in the field value. In such case I would suggest to create a field in the table for sorting purposes and populate it based on insert and update triggers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

look at this table please table |id| |name| |order| i must get the rows,
Please look at this query. select name form table Let suppose this returns 100
Please look at this picture: Is it possible to find per-column sum for all
Please look into the below query declare @t table(roleid int null,EmailAddress varchar(50) null) insert
if i use this query thath creates a table(look Table1), But VisitingGap column is
Please tell me how can I get array of all Those DIV of specific
Can someone please tell me how to show all privileges/rules from a specific user
Please check my website out: http://www.budgie.richardcmpage.com/index.php I've tried all sorts and can't get the
can u please tell me how to write regular expression to match all time
please try this link for getting my code. its working in all browsers not

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.