问题
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