SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

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

By Mike Arney, 2008/08/04

Total article views: 896 | Views in the last 30 days: 18

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');

By Mike Arney, 2008/08/04

Total article views: 896 | Views in the last 30 days: 18
Your response
 
 
Related tags

T-SQL    
 
 
Contribute

Free registration required...

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Login (existing users)

Login

Email:   Password:   Remember me: Forgotten your password?

Register (new users)

Register

Email:   Password:
Confirm:

Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

Steve Jones
Editor, SQLServerCentral.com