Tuesday, December 24, 2024

SQL Server ASCII() Function

 In SQL Server, the ASCII() function is used to return the ASCII value of the leftmost character of a string. The ASCII value corresponds to the character's position in the ASCII character set.

Syntax:

ASCII ( character_expression )
  • character_expression: A character or an expression that evaluates to a character data type (such as CHAR, VARCHAR, TEXT, etc.). This can be a string or a column name containing character data.

Example:

SELECT ASCII('A');  -- Returns 65
SELECT ASCII('a');  -- Returns 97
SELECT ASCII('1');  -- Returns 49
SELECT ASCII('!');  -- Returns 33

Explanation:

  • The ASCII() function returns the ASCII value of the first character of the string.
  • For example, 'A' corresponds to 65 in ASCII, while 'a' corresponds to 97.

Usage:

  • The ASCII() function is useful when working with character data and performing operations based on character encoding or comparing character values numerically.

Let me know if you need further examples or details!

No comments:

Post a Comment