Below are some transact SQL (MS-SQL Server) statements that I ran in Query
Analyzer. I'm trying to figure out how it is that a UUID in character format
translates to the hexidecimal format SQLServer uses.

An example is:
String format is: B4F00409-CEF8-4822-802C-DEB20704C365
Hexidecimal format is: 0x0904F0B4F8CE2248802CDEB20704C365
I see a pattern, but I can't explain it. My first thought was that it's an
endian problem, but that doesn't seem to pan out. Anyone have any ideas?

The pattern I see is the last 2 fields are the same. But the high order
bytes / half are swapped
B4F00409-CEF8-4822-802C-DEB20704C365
  \ /     \/   \/  |||| ||||||||||||
  / \     /\   /\  |||| ||||||||||||
0904F0B4 F8CE 2248 802C DEB20704C365


//T-SQL Statements
DECLARE @tmpuuid uniqueidentifier
DECLARE @myuuid uniqueidentifier

SET @myuuid = newid()

print 'MyUUID String Format: '
print Convert(char(36), @myuuid)
print ''
print 'MyUUID Binary Format: '
print Convert(binary(16), @myuuid)
print ''
SET @tmpuuid = Convert(binary(16), @myuuid)
print 'tmpuuid converted back: '
print @tmpuuid

==OUTPUT==
MyUUID String Format:
B4F00409-CEF8-4822-802C-DEB20704C365

MyUUID Binary Format:
0x0904F0B4F8CE2248 802CDEB20704C365

tmpuuid converted back:
B4F00409-CEF8-4822-802C-DEB20704C365

== Reformatted ==
MyUUID String Format:
B4 F0 04 09 - CE F8- 48 22- 802C-DEB20704C365

MyUUID Binary Format:
0x 09 04 F0 B4 F8 CE 22 48  802C DEB20704C365

tmpuuid converted back:
B4F00409-CEF8-4822-802C-DEB20704C365


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to