Brettb.Com
  HOME | ABOUT ME | BIOTECHNOLOGY | ARTICLES | GALLERY | CONTACT
Search: Go
TECHNICAL ARTICLES
 ASP
 ASP.NET
 JavaScript
 Transact SQL
 Other Articles
 Software Reviews

PHOTO GALLERIES
 Canon EOS 300D Samples
 Akihabara Maids!
 More Galleries...

TRAVEL LOG
 2009: China
 2008: Tokyo
 2007: Tokyo
 2006: Hong Kong
 2005: New York City

MORE STUFF
 Search Engine Optimisation
 Build an ASP Search Engine
 My Tropical Fishtank
 Autoglass
 SQL Month Name
 SQL Get Date Today
 SQL Year Month
 Other New Stuff...

POPULAR STUFF
 Regular Expressions
 Index Server & ASP
 JavaScript Ad Rotator

Home > Articles > Transact SQL Programming Articles

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

ASCII

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.

CHAR

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

Useful Links

  • The SQL Documentation Tool creates technical documentation for Microsoft SQL Server databases. A free trial version is available for download.

  Site Map | Privacy Policy

All content is 1995 - 2012