I want to get the SHA1 Hash of MATKHAU in SQL Server 2019 so I use HASHBYTES. But as you see the value of SELECT HASHBYTES is different from the value when I use Store Procedure. What's wrong with it? (It's the same input in MATKHAU)
1 Answer
Data types matter:
SELECT HASHBYTES('SHA1', '123'); -- here VARCHAR
vs
SELECT HASHBYTES('SHA1', N'123'); -- here NVARCHAR
The stored procedure takes parameter as NVARCHAR which causes implicit conversion when providing parameter to EXEC.
2 Comments
Quyên Nguyễn
Thanks. Finally can fix it
Lukasz Szozda
@QuyênNguyễn Glad to hear that. How does accepting an answer work?
