SQL Server 2016-2022 HASHBYTES fails SHA224, SHA256, SHA384, SHA512

Anonymous
2025-03-19T15:38:11.3233333+00:00

These queries should not return null but they two on several machines where I have run them as a test:
Is there a fix? I have the latest versions from Windows Catalog
Microsoft SQL Server 2016 (SP3-GDR) (KB5046855) - 13.0.6455.2 (X64)

Oct 15 2024 11:23:31 

Copyright (c) Microsoft Corporation

Enterprise Edition (64-bit) on Windows 10 Enterprise 10.0 <X64> (Build 22631: ) (Hypervisor)  

and SQL 2022 kb5050771 from four days ago.

SELECT HASHBYTES('MD5', CAST('test' AS varbinary(max))); -- Test with MD5 not null

SELECT HASHBYTES('SHA1', CAST('test' AS varbinary(max))); -- Test with SHA1 not null

SELECT HASHBYTES('SHA256', CAST('test' AS varbinary(max))); -- Test with SHA256 null

SELECT HASHBYTES('SHA224', CAST('test' AS varbinary(max))); -- Test with SHA224 null

SELECT HASHBYTES('SHA384', CAST('test' AS varbinary(max))); -- Test with SHA384 null

SELECT HASHBYTES('SHA512', CAST('test' AS varbinary(max))); -- Test with SHA512 null

SELECT HASHBYTES('SHA2_512', CAST('test' AS varbinary(max))); -- Test with SHA2_512 not null

SELECT HASHBYTES('SHA2_256', CAST('test' AS varbinary(max))); -- Test with SHA2_512 not null

SQL Server | SQL Server Transact-SQL
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 128.7K Reputation points MVP Volunteer Moderator
    2025-03-19T22:45:57.8+00:00

    The syntax graph for HASHBYTES goes:
    User's image

    So SHAxxx is not there and have never been. They might have been in Visual Studio, but Visual Studio is not SQL Server.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.