How to replicate a computed hashed value in a SQL table?

↘锁芯ラ 提交于 2020-07-23 06:21:27

问题


We have a column in a table that is a computed HASH:

My question is, how do I replicate that computed value so that I can join on it? For example, given this row:

I am trying this:

select (CONVERT([uniqueidentifier],hashbytes('MD2',concat('ABC-123','en'))));

Where ABC-123 would be the value for Phrase. But that gives me a very different hash value:

A549AB46-7111-6833-F5A9-C0102F63E822

I assume because it's not using the same uniqueidentifier?

What do I need to do so that I can replicate the original computed and stored hash value?


回答1:


You have to hash the same data type. So convert the target phrase to nvarchar(max) before hashing, and it should match. EG

CONVERT([uniqueidentifier],hashbytes('MD2',cast(concat('ABC-123' ,'en') as nvarchar(max))))


来源:https://stackoverflow.com/questions/62838849/how-to-replicate-a-computed-hashed-value-in-a-sql-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!