ALTER FUNCTION [dbo].[Str2Uniqe](@s VARCHAR(50))
RETURNS UNIQUEIDENTIFIER
AS BEGIN
SET @s = REPLACE(REPLACE(@s,'0x',''),'-','')
SET @s = STUFF(STUFF(STUFF(STUFF(@s,21,0,'-'),17,0,'-'),13,0,'-'),9,0,'-')
RETURN CAST(@s AS UNIQUEIDENTIFIER)
END
Select created function result as given below.
DECLARE @guid VARCHAR(50)
SET @guid = '3b8766fa720043af9e21c5bc6bbbdea5'
SELECT dbo.Str2Uniqe(@guid)
Result as given below.
Result as given below.