create function [dbo].[GetMd5Hash] (@raw nvarchar(max)) returns uniqueidentifier as
begin
declare @hexstring char(32)
select @hexstring = master.dbo.fn_varbintohexsubstring(0, hashbytes('MD5', @raw), 1, 0)
return CAST(SUBSTRING(@hexstring, 1, 8)
+ '-' + SUBSTRING(@hexstring, 9, 4)
+ '-' + SUBSTRING(@hexstring, 13, 4)
+ '-' + SUBSTRING(@hexstring, 17, 4)
+ '-' + SUBSTRING(@hexstring, 21, 12) as uniqueidentifier)
end
2 comments:
Is there no built-in MD5 function in Sql Server?
@sha1_hash There sorta is. hashbytes() does the md5 conversion but returns a string. I prefer to store the hash as a uuid.
Post a Comment