0

enter image description here

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 1

1

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.

db<>fiddle demo

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Finally can fix it
@QuyênNguyễn Glad to hear that. How does accepting an answer work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.