Convert from UniqueIdentifier to BigInt and Back?

后端 未结 1 1907
-上瘾入骨i
-上瘾入骨i 2021-01-04 04:46
declare @uu uniqueidentifier =  \'C50B0567-F8CC-4219-A1E1-91C97BD9AE1B\'
select @uu
declare @zaza bigint = ( select convert(bigint, convert (varbinary(8), @uu, 1)) )         


        
相关标签:
1条回答
  • 2021-01-04 05:06

    There is no problem with your second convert. When I run your SQL statement in SQL management studio, I get:

    ------------------------------------
    C50B0567-F8CC-4219-A1E1-91C97BD9AE1B
    
    (1 row(s) affected)
    
    
    --------------------
    7423352504965404994
    
    (1 row(s) affected)
    
    
    ------------------------------------
    C50B0567-F8CC-4219-0000-000000000000
    
    (1 row(s) affected)
    

    Since you are converting 8 byte value to 16-byte guid, half of guid will be zeroes, which is exactly what you are seeing.

    0 讨论(0)
提交回复
热议问题