Google Ads

Friday, January 1, 2010

Binary checksum does not consider more than 255 characters in Microsoft SQL Server

     Binary checksum in Microsoft SQL Server is a good function to compare strings in data base without affecting performance of queries. The function Binary_CheckSum() will genreate a checksum for the string entered in the specified column and it will be easier and faster to compare that integer value rather than comparing the strings. The benefit of using Binary_CheckSum() instead of checksum() is that it is case sensitive as it uses the ASCII value of each character and  calculates the Binary_CheckSum().

     But think twice before using these functions for large strings. These functions will consider only 255 characters. If the character length exceeds 255 characters, the check sum will reset and start again and consider characters greater than 256 only. So, for example, the computed Binary checksum of the single character 'a' will be same as that of a 257 character string whose last character is 'a'.

Wednesday, December 30, 2009

Array functions in JavaScript

Here are some of the functions useful for array operations

Push() - Appends one or more elements to the end of an array

var data = [ "A" ];
data.push( "B" );
data.push( "C" );

data = ["A","B","C"]

Pop() - Pops out (removes) one element from the end of an array

var data = ["A","B","C"];

data = ["A","B"];

Unshift() - Adds one or more elements to the beginning of an array

var data = [ "A" ];
data.unshift( "B","X" );
data.unshift( "C" );

data = ["C","B","X","A"]

Shift() - Removes one element from the beginning of an array

var data = ["A","B","C"];

data = ["B","C"];

Splice() - Removes elements specified number of items from the starting index and also optionally allows insertion of items on the start index.

// array.splice(start Position,number of elements,[elements to be inserted])

var data = ["A","B","C","D"];

["B", "C"]
["A", "x", "y", "D"]

Thanks to Ben Nadel for sharing this useful piece of information.