How to sort GUID's the SQL Server way using Delphi

In a project I am working on it would be nice if I can sort an in memory list of guids and compare against a SQL server table ordered by these same guids. Unfortunately when an ordered list is returned by SQL Server, the order is not immediately apparent.

What would be the best way to sort this in memory list so that the order is the same as would be returned by SQL Server?

For example, a query "SELECT ID FROM TABLE1 ORDER BY ID" returns:


For the sake of this question, assume I have an array of strings which contain the guid values above, however in the following order:


I want to see that I am missing one from the SQL query, and have one that the SQL query did not have. The quickest way is obviously to have both lists sorted the same way, but I do not want to perform a query such as "SELECT ID FROM TABLE1 ORDER BY cast(ID as varchar(100))" but would rather fix the sort on the Delphi side.


Alberto Ferrari has written a blog entry about it. From there:

0 1 2 3  4 5  6 7  8 9  A B C D E F
  • 0..3 are evaluated in left to right order and are the less important, then
  • 4..5 are evaluated in left to right order, then
  • 6..7 are evaluated in left to right order, then
  • 8..9 are evaluated in right to left order, then
  • A..F are evaluated in right to left order and are the most important

Need Your Help

Is there documentation on how to upgrade a Joomla extension from 1.5 to 2.5

joomla migrate

I'm in the process of migrating my Joomla 1.5 web site to Joomla 2.5. I'm using all of the migration tools available, but I have a few, key, extensions, most of which are pretty simple, that are not

Why does vector not have sort() method as a member function of vector, while list does?

c++ sorting stl vector

There is a sort() method for lists in STL. Which is absurd, because I would be more inclined to sort an array/vector.