Questions tagged [hashbytes]

A hashing function within the Microsoft Transact-SQL Database Engine.

A hashing function within the Microsoft Transact-SQL Database Engine which supports the following algorithms:

  • MD2
  • MD4
  • MD5
  • SHA
  • SHA1
  • SHA2_256
  • SHA2_512

Resources

62 questions
12
votes
4 answers

SQL Server 2014 Hashbytes of a nvarchar(max) result is nvarchar(max)

Using SQL Server 2014 I have a table that has a nvarchar(max) column called [ASCII File] which can contain an ASCII text file of many K. I then want to do a MD5 hashbytes on that file and the resultant hash should always be 20 bytes. Well when I do…
John
  • 131
  • 1
  • 1
  • 8
11
votes
1 answer

Binary_Checksum Vs HashBytes function

I have a complex query which uses a lot of binary checksum function, when I was testing it with some test data for two distinct records it actually returned me same checksum value. Please find the test data I used below SELECT BINARY_CHECKSUM(16 …
Prakazz
  • 421
  • 1
  • 8
  • 21
4
votes
1 answer

SHA256 doesn't yield same result between C# and SQL Server when using Spanish words

I am using SHA256 to get a hashed hexadecimal string. It works fine when using regular characters, however when a string to be hashed includes accents/diacritics, then I get a different result in C# and T-SQL. I would prefer to make the change on…
TheProgrammer
  • 1,314
  • 5
  • 22
  • 44
3
votes
1 answer

HASHBYTES, sha2_256 in sql introduce bad characters when called from python

One of our old sql legacy code, converts a numerical column in sql using the HASHBYTES function and sha2_256. The entire process is moving to python as we are putting in some advanced usage on top of the legacy work. However, when using connector,…
2
votes
0 answers

Why does varchar(max) column in concat function cause query plan to blow up

Context Tables ranging from 1M - 200M records. All tables in question have zero indexes on them as they are staging/landing areas for our raw data sources. The purpose of having cast(NULL as varchar(max)) below was to handle 1 situation where our…
Adam
  • 2,422
  • 18
  • 29
2
votes
2 answers

SQL Uniqueidentifier and hashbytes does not match with c#

Creating hash with c# is different when same done in SQL server. why not same? using (SHA1Managed sha1 = new SHA1Managed()) { Guid g = new Guid("81FE483B-39ED-4052-8FFC-55A710907D9B"); var appGateId = g.ToString(); var hash =…
2
votes
2 answers

SHA1 value for latin characters in SQL server not matching with SHA1 of snowflake database

I am trying to match the sha1 values of certain data in the table in SQL Server and Snowflake. I've got the sha1 for a latin character in SQL server in the following way- select sys.fn_varbintohexsubstring(0, HASHBYTES('SHA1',cast('á' as…
2
votes
0 answers

SQL Azure HashBytes performance - wide variance

Up until a few days ago, T-SQL code we have running in SQL Azure that generates an MD5 for temp table values was fast (a few seconds per hundred thousand on a Business Critical Gen 5, 2 VCores DB). Recently we noticed from our logs that on multiple…
Vince
  • 583
  • 5
  • 20
2
votes
1 answer

Hashes Are Not Matching

I am hashing the same values, but am getting different results. Here is a simplified example to explain what I am encountering: I have a dimension table that looks like this: gender gender_id Male 1 Female 0 The datatype for gender is…
M. Palmer
  • 88
  • 6
2
votes
1 answer

SSIS Violation of PRIMARY Key Constraint Error with Column Generated by HASHBYTES SHA2-256 Function

I have come across a problem that is beyond my Googling abilities, and I would appreciate any help at all. I've created a very simple SSIS package to copy data from a source table in an Azure SQL database to a target in an MS SQL Database using an…
2
votes
1 answer

Hashbytes equivalent in MySQL

I am moving my data from SQL Server to MySQL. The data is moving without any issues, but I am trying to come up with a way to validate the integrity of the data between SQL Server and MySQL. I am having issues with regards datatypes VARCHAR and…
arsm4
  • 101
  • 2
  • 10
2
votes
2 answers

SQL HASHBYTES function returns weird output when used in CASE WHEN/IIF

I have written a stored procedure that hashes the value of a certain column. I need to use this HASHBYTES function in a CASE WHEN or IIF statement, like this: DECLARE @Hash varchar(255) = 'testvalue' SELECT IIF(1=1, HASHBYTES('SHA1',@Hash),…
JVGBI
  • 565
  • 1
  • 8
  • 26
2
votes
1 answer

SQL Server : Hashbytes with Umlauts

I have a strange situation figured out, when the Hashbyte function of SQL Server is not outputting the correct result when converting it to SHA2_256 with a string containing umlauts (ä,ö,ü,ß). I run the example code in SQL Server: declare…
Rockstaa
  • 23
  • 3
2
votes
1 answer

Need C# equivalent for the below SQL HashBytes function

I have created hash value using below function in sql SQL query Select hashbytes('MD5', PNumber+CONVERT(VARCHAR(50),cast(datestamp as binary),1)) From dbo.Events Now I need to get the equivalent C# function in order to get the hash value and…
Chandra Mohan
  • 729
  • 2
  • 10
  • 29
2
votes
2 answers

SQL Server HashBytes Function

Can someone please tell me why I'm getting different answers for the following: Here is a very simple function used to return the hash Value: CREATE Function [fn_GetPin](@strText VARCHAR(254)) RETURNS VARCHAR(254) AS BEGIN SET @strText =…
iamtheoracle
  • 317
  • 2
  • 11
1
2 3 4 5