SQL Server 2008 GUID Sort

What is the best way to sort records in Guid. The correct results are never given below.

With UIDs As (-- Select ID = 1, UID = NEWID() Union Select ID = 2, UID = NEWID() Union Select ID = 3, UID = NEWID() Union Select ID = 4, UID = NEWID() Union Select ID = 5, UID = NEWID() Union Select ID = 6, UID = NEWID() Union Select ID = 7, UID = NEWID() Union Select ID = 8, UID = NEWID() Union Select ID = 9, UID = NEWID() Union Select ID = 10, UID = NEWID() Union Select ID = 11, UID = NEWID() Union Select ID = 12, UID = NEWID() Union Select ID = 13, UID = NEWID() Union Select ID = 14, UID = NEWID() Union Select ID = 15, UID = NEWID() Union Select ID = 16, UID = NEWID() ) Select * From UIDs Order BY UID, ID 

Instead of using Guid, how can I generate consecutive integers in my choice.

thanks

+4
source share
2 answers

Not the best answer.

This explains how SQL Server: How are GUIDs sorted by SQL Server sorted?

You have a NEWSEQUENTIALID , but it is not guaranteed to sort as you expect. And why use a GUID when you have ranking functions?

+4
source
 SELECT * FROM myTable ORDER BY CAST(myGuid AS VARCHAR(36)) 
+12
source

All Articles