Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favourite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved 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: 1046 | Views in the last 30 days: 1
 
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

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones