Posted by Steve Kass on 06/25/05 21:59
Orly,
Here is what I believe it does for a single varchar
column. It's not a particularly good hash function at
all.
create function binary_checksum_varchar (
@t varchar(1000)
) returns int as begin
declare @b bigint set @b = 0
declare @c tinyint
declare @s bit set @s = 0
declare @i int set @i = 1
while @i <= len(@t) begin
set @c = ascii(substring(@t,@i,1))
set @b = @b / 16 * 16 + @b % 16 ^ @c / 16
set @b = @b * 16 + @c % 16
if @c >= 128 begin
set @b = @b ^ 0xFF
set @s = 1 - @s
end
set @b = @b % 0x0100000000 ^ @b / 0x0100000000
set @i = @i + 1
end
if @s = 1 set @b = @b ^ 0xFFFFFFFF
if @b >= 0x80000000 set @b = @b | 0xFFFFFFFF00000000
return @b
end
go
You'll find more information if some of the threads
here:
http://groups.google.co.uk/groups?q=binary_checksum+kass+sqlserver
Steve Kass
Drew University
Orly Junior wrote:
> Hello,
>
> Do you know if the algorithm for the BINARY_CHECKSUM function in documented
> somewhere?
> I would like to use it to avoid returning some string fields from the
> server.
> By returning only the checksum I could lookup the string in a hashtable and
> I think this could make the code more efficient on slow connections.
>
> Thanks in advanced and kind regards,
>
> Orly Junior
>
>
>
[Back to original message]
|