Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Java's String.hashCode() function in T-SQL

By Mike Arney,

Pass the function a string, it returns an integer hash of the string. If you don't need to match Java, use the T-SQL binary_checksum() function, which will be much faster. (By the way, it looks like binary_checksum() uses a very similar algorithm: for all caps string, I get very similar results if instead of the "@h*31" in the code above I use "@h*16", and instead of "%4294967296" use "%4294967295". There must be something else too...).

Example:

select dbo.UTIL_JAVA_HASHCODE('abC1234567');

Total article views: 1061 | Views in the last 30 days: 3
 
Related Articles
FORUM

string Comparison.

'string' = 'string___' ???

FORUM

Manipulate String

String Output

FORUM

csv string

csv string

FORUM

string formatting

String Formatting

FORUM

parse/split string

string manipulation

Tags
t-sql    
 
Contribute