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

  • Home
  • SEARCH
  • 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 8655669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:05:20+00:00 2026-06-12T15:05:20+00:00

I need to sort my SQL stored procedure recordset (shown below) alphabetically (by CustomerName),

  • 0

I need to sort my SQL stored procedure recordset (shown below) alphabetically (by CustomerName), but also maintaining the sequential order of RecordID (meaning RecordID 2 is above RecordID 3, in relation to ParentID & ID fields). Any suggestions?

ID           ParentID         RecordID        CustomerName
53445347        5344        2                 Witt - 47
534453475345    53445347    3                 Witt - 45
534453475346    53445347    3                 Witt - 46
53445351        5344        2                 Sjob - 51
534453515348    53445351    3                 Sjob - 48
534453515349    53445351    3                 Sjob - 49
534453515350    53445351    3                 Sjob - 50
53445357        5344        2                 Hal - 57
534453575355    53445357    3                 Hal - 55
534453575356    53445357    3                 Hal - 56
534453577252    53445357    3                 Hal - 52
53446852        5344        2                 Boston, - 52
534468526850    53446852    3                 Boston, - 50
534468526851    53446852    3                 Boston, - 51
534468527205    53446852    3                 Boston, - 05
53447884        5344        2                 Agri - 84
534478847883    53447884    3                 Agri - 83
534478847957    53447884    3                 Agri - 57

The intended output would be like:

53447884        5344        2                 Agri - 84
534478847883    53447884    3                 Agri - 83
534478847957    53447884    3                 Agri - 57
53446852        5344        2                 Boston, - 52
534468526850    53446852    3                 Boston, - 50
534468526851    53446852    3                 Boston, - 51
534468527205    53446852    3                 Boston, - 05
53445357        5344        2                 Hal - 57
534453575355    53445357    3                 Hal - 55
534453575356    53445357    3                 Hal - 56
534453577252    53445357    3                 Hal - 52
53445351        5344        2                 Sjob - 51
534453515348    53445351    3                 Sjob - 48
534453515349    53445351    3                 Sjob - 49
534453515350    53445351    3                 Sjob - 50
53445347        5344        2                 Witt - 47
534453475345    53445347    3                 Witt - 45
534453475346    53445347    3                 Witt - 46
  • 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-12T15:05:21+00:00Added an answer on June 12, 2026 at 3:05 pm

    if all your Customer names are formed as in your sample :

    ORDER BY SUBSTRING( CustomerName, 0, CHARINDEX( '-', CustomerName)), RecordID
    

    By the way, if you have any chance to change your model, split the alpha and the numeric part of CustomerName in two fields, and your life will be better, and the world will be as one.

    If you can have customer names without the -

    Rather try

    ORDER BY  CASE WHEN CHARINDEX('-', CustomerName) = 0 
                   THEN CustomerName
                   ELSE SUBSTRING( CustomerName, 0, CHARINDEX( '-', CustomerName))
                END,
                RecordID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've the following MS SQL stored procedure. I need to sort the results without
I need to sort list of strings in the alphabetical order: List<String> list =
In my stored procedure I need a single parameter that will give me a
I am working on a stored procedure in SQL Server 2008 for resetting an
I have need of some logic in a stored procedure. All the stored procedure
I have a stored procedure running on sql server 2008 looping over a table
I need to manually migrate modified stored procedures from a DEV SQL Server 2005
Am newbie to SQL Server. In that i need to sort the following data
I need to sort a flat file by third column leaving first column intact
I need to sort nodes in xml. I have the following code which successfully

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.