1. DECLARE @myguid uniqueidentifier = NEWID();
    2. DECLARE @myguid36 VARCHAR(36)
    3. SELECT @myguid36=REPLACE(CAST(@myguid AS VARCHAR(36)),'-','')
    4. SELECT @myguid36=UPPER(REPLACE(CAST(@myguid AS VARCHAR(36)),'-',''))--转大写
    5. SELECT @myguid36=LOWER(REPLACE(CAST(@myguid AS VARCHAR(36)),'-',''))--转小写
    6. SELECT @myguid,@myguid36,CONVERT(uniqueidentifier,STUFF(STUFF(STUFF(STUFF(@myguid36,9,0,'-'),14,0,'-'),19,0,'-'),24,0,'-'))
    1. SELECT CONVERT(uniqueidentifier,LEFT(C, 8)
    2. + '-' +RIGHT(LEFT(C, 12), 4)
    3. + '-' +RIGHT(LEFT(C, 16), 4)
    4. + '-' +RIGHT(LEFT(C, 20), 4)
    5. + '-' +RIGHT(C, 12))
    1. create function str2uniq(@s varchar(50)) returns uniqueidentifier as begin
    2. -- just in case it came in with 0x prefix or dashes...
    3. set @s = replace(replace(@s,'0x',''),'-','')
    4. -- inject dashes in the right places
    5. set @s = stuff(stuff(stuff(stuff(@s,21,0,'-'),17,0,'-'),13,0,'-'),9,0,'-')
    6. return cast(@s as uniqueidentifier)
    7. end

    https://stackoverflow.com/questions/1390109/convert-varchar-to-uniqueidentifier-in-sql-server https://stackoverflow.com/questions/16222343/convert-guid-to-varchar32/16222390