Another Interesting Sort

Categories: News, Professional, SSC, SSSOLV
Tags: ,
Comments: No Comments
Published on: March 19, 2012

In October of 2011, I shared an example of a peculiar set of sort requirements.  Today, I am going to share another similar set of requirements.  Based on prior experience, when I saw this request on a sort order, I was sure I could find a simpler solution.  Today, I will share the requirements and solution with you.


Given a set of characters, you must be able to sort according to the following:

  1. !
  2. $
  3. ?
  4. @
  5. ^
  6. {
  7. >
  8. ASCII values


To demonstrate the requirements and solution, let’s create a temp table and populate it with some values like those in the requirements.

[codesyntax lang=”tsql”]



[codesyntax lang=”tsql”]


Sometimes the simplest solution requires a lot of testing.  When I came across the requirements, I thought it could be solved via a collation.  The problem was that I did not know which collation.  I had to test a few collations to find the collation that would create the correct result set.  If you are interested in learning about other collations, you can read this article.

No Comments - Leave a comment

Leave a comment

Your email address will not be published. Required fields are marked *

March 2012
« Feb   Apr »


  • @Flowfields_: RT @Ko_Ver: Anyone having issues using custom visuals in #PowerBI using the June update? Visuals not showing and icons are not displayed. #…
  • @Ko_Ver: Anyone having issues using custom visuals in #PowerBI using the June update? Visuals not showing and icons are not displayed. #sqlhelp
  • @abhineetsr: Delete TOP.... is just like a Boon 😀 When you have to delete the column in Table who have no unique column 👍 #sql #sqlhelp #javascript
  • @SQLSoldier: @vdamu Same true for anything outside of the AG database. Logins, jobs, server-level triggers, etc. #sqlhelp
  • @SQLSoldier: @vdamu You have to create the linked server on all nodes. Linked servers exist in master database so not transferred by AG. #sqlhelp
  • @vdamu: #sqlhelp 2/3 to use the 4 part name? Any pointers would be greatly appreciated.
  • @vdamu: #sqlhelp 2/3 availability group setup. Works fine in regular cluster, but not in AlwaysOn setup. How to configure linkedserver in AlwaysOn
  • @vdamu: #sqlhelp 1/2 Getting "Could not find server 'Server1' in sys.servers" when executing a sp that has a query with 4 part name in AlwaysOn
  • @SQLSoldier: @BooseTV Not many MySQL people on this hash tag (used primarily for SQL Server), but have you tried this? #sqlhelp
  • @BooseTV: Any #sqlhelp out there? Every time i restart my pc/ server mysql resets to strict mode, changing my config doesnt seem to work

Welcome , today is Monday, July 25, 2016