Tuesday, December 24, 2024

SQL Server CHAR() Function

 In SQL Server, the CHAR() function is used to return the character for a given integer ASCII code. The function takes a single integer argument and returns the corresponding character.

Syntax:

CHAR(integer_expression)
  • integer_expression: This is the ASCII value (an integer between 0 and 255) for which you want to get the corresponding character.

Example:

SELECT CHAR(65) AS CharOutput;

Output:

CharOutput
-----------
A

In this example, CHAR(65) returns the character 'A' because 65 is the ASCII code for the letter 'A'.

Notes:

  • The ASCII value must be between 0 and 255.
  • If the integer is outside this range, SQL Server will return an error.

No comments:

Post a Comment