如何在SQL表中复制计算出的哈希值? [英] How to replicate a computed hashed value in a SQL table?
问题描述
我们在表中有一列是经过计算的HASH:
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:
我正在尝试:
select (CONVERT([uniqueidentifier],hashbytes('MD2',concat('ABC-123','en'))));
ABC-123
是Phrase
的值.但这给了我一个非常不同的哈希值:
Where ABC-123
would be the value for Phrase
. But that gives me a very different hash value:
A549AB46-7111-6833-F5A9-C0102F63E822
A549AB46-7111-6833-F5A9-C0102F63E822
我认为是因为它没有使用相同的uniqueidentifier
?
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?
推荐答案
您必须对相同的数据类型进行哈希处理.因此,在散列之前将目标短语转换为nvarchar(max)
,并且它应该匹配. EG
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))))
这篇关于如何在SQL表中复制计算出的哈希值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!