Posts

Showing posts with the label GUID

SQL Server Hole #1

Image
In my opinion SQL Server 2005 is full of holes, and my definition is functionality that is available doesn't span the whole gamete of the server.  For example, aggregates don't work with GUIDs (call uniqueidentifiers in SQL).  Here is non-working code that I would like to see work: CREATE #Temp(Id uniqueidentifier , Name varchar (50)) SELECT MAX (Id) FROM #Temp DROP TABLE #Temp Why doesn't this work?  GUIDs are just 128-bit numbers, they are all unique and one comes before the other, there should be a MAX and MIN.  This does work: CREATE #Temp(Id uniqueidentifier , Name varchar (50)) SELECT MAX ( CONVERT ( varchar (41),Id)) FROM #Temp DROP TABLE #Temp However, I don't want the extra overhead of converting each GUID to a String.    

C++ GUIDs

Image
If you are converting a GUID to a String in C++ you can use this Windows API: TCHAR szString[41]; ::StringFromGUID2(guid, szString, 41); Note that C++ adds brackets around the GUID so it appears like this: {c200e360-38c5-11ce-ae62-08002b2b79ef} However, if you are doing a ToString() in C# you don't get the ending brackets, for example: String output = Guid.NewGuid().ToString(); Will return: c200e360-38c5-11ce-ae62-08002b2b79ef C# will parse a string into a GUID regardless of the brackets.  For example, both these get you the same GUID: System.Guid guid = new System.Guid( "c200e360-38c5-11ce-ae62-08002b2b79ef" ); System.Guid guid2 = new System.Guid( "{c200e360-38c5-11ce-ae62-08002b2b79ef}" ); The equivalent function in C++ is: ::CLSIDFromString(sz,&guid); However, CLSIDFromtString will not accept a GUID without brackets.  Note here that CLSID, IID and GUID are the same in C++. If you are going between C++ and C# and you are passing GUIDs as str...