sql - hash several strings tsql -
i trying create unique hash this:
select cast(hashbytes('sha1', ltrim(rtrim(isnull('9',''))) + ltrim(rtrim(isnull('x',''))) + ltrim(rtrim(isnull('',''))) + ltrim(rtrim(isnull('y',''))) + ltrim(rtrim(isnull('','')))) varbinary(20)) select cast(hashbytes('sha1', ltrim(rtrim(isnull('9',''))) + ltrim(rtrim(isnull('x',''))) + ltrim(rtrim(isnull('y',''))) + ltrim(rtrim(isnull('',''))) + ltrim(rtrim(isnull('','')))) varbinary(20))
unfortunately, end same hash despite different strings. ideas why?
ps:
this solves above 'issue':
select ltrim(rtrim(isnull('9', '-'))) + n',' + ltrim(rtrim(isnull('x', '-'))) + n',' + ltrim(rtrim(isnull('', '-'))) + n',' + ltrim(rtrim(isnull('y', '-'))) + n',' + ltrim(rtrim(isnull('', '-'))) , cast(hashbytes('sha1', ltrim(rtrim(isnull('9', '-'))) + n',' + ltrim(rtrim(isnull('x', '-'))) + n',' + ltrim(rtrim(isnull('', '-'))) + n',' + ltrim(rtrim(isnull('y', '-'))) + n',' + ltrim(rtrim(isnull('', '-')))) varbinary(20)) select ltrim(rtrim(isnull('9', '-'))) + n',' + ltrim(rtrim(isnull('x', '-'))) + n',' + ltrim(rtrim(isnull('y', '-'))) + n',' + ltrim(rtrim(isnull('', '-'))) + n',' + ltrim(rtrim(isnull('', '-'))) , cast(hashbytes('sha1', ltrim(rtrim(isnull('9', '-'))) + n',' + ltrim(rtrim(isnull('x', '-'))) + n',' + ltrim(rtrim(isnull('y', '-'))) + n',' + ltrim(rtrim(isnull('', '-'))) + n',' + ltrim(rtrim(isnull('', '-')))) varbinary(20))
because there not different strigns:
ltrim(rtrim(isnull('9',''))) + ltrim(rtrim(isnull('x',''))) + ltrim(rtrim(isnull('',''))) + ltrim(rtrim(isnull('y',''))) + ltrim(rtrim(isnull('','')))) -- same of ltrim(rtrim(isnull('9',''))) + ltrim(rtrim(isnull('x',''))) + ltrim(rtrim(isnull('y',''))) + ltrim(rtrim(isnull('',''))) + ltrim(rtrim(isnull('','')))) -- same of '9xy'
Comments
Post a Comment