Transact SQL Other Articles Software Reviews
Using the Transact SQL ASCII and Char Functions
The SQL Server Transact SQL functions ASCII and CHAR can be used to determine the character code of an ASCII character and . As such the functions are useful for when writing SQL statements to encode or decode text strings. The functions are similar to the Chr and Asc functions within VBScript and Visual Basic 6.0
The ASCII function can be used to return the character code of a specific ASCII character. The following Transact SQL statement returns the ASCII character code for the letter 'a', which is 97:
select ascii('a') as CharacterCode
Note that if a string of more than one characters is supplied as the ASCII function's argument, only the corresponding character code of the first character is returned.
The CHAR function can be used to return the character corresponding to a specific ASCII code. The following Transact SQL statement returns the ASCII character corresponding to the code of 120, which is 'x':
select char(120) as ASCIICharacter