SQL CHAR | SQL Server CHAR() Function With Example

Summary: in this tutorial, you will learn SQL CHAR Function and how to use the CHAR() function in SQL Server to convert an ASCII code value to a character. This is most popular string function in SQL.

Definition and Usage

The CHAR() function returns the character which is based on the ASCII code. The CHAR() function converts an ASCII value to a character value. Furthermore, let see the syntax of the CHAR() function in SQL Server.

SQL CHAR() Function Synatx

There are the following synatx:

CHAR ( int_exp )

Parameter Values

Parameter Description
int_exp Required. in this syntax, the int_expr is an integer expression, which evaluates to an integer whose value from 0 to 255. Therefore, if the integer expression evaluates to a value that is outside of this range, then the CHAR() function returns NULL.
.
Note: The CHAR() function returns a character whose data type is CHAR(1).
To convert a character to an ASCII value, then you use the ASCII() function

SQL CHAR() Function Example:

Therefore, the following as given below example uses the CHAR() function to get the characters of the number 65, 72, 89, and 90.

Therefore, let’s execute the query to return the output.

SQL CHAR Function

NOTE 1:

Furthermore, Let’s see the following statement will returns the NULL because the argument is out of the range from 0 through 255


The following shows the output:

NOTE 2:

Therefore, the following given below example uses the CHAR function in SQL Server to concat two strings. However, the 2nd (second) string is placed in the new line:

Let’s execute the query to return the output.

Therefore, In the above example, the CHAR 10 will returns the new line character, furthermore, the second string is placed in the new line.

Conclusion

In this tutorial, you have learned CHAR() Function and also how to use the CHAR() function in SQL Server to get a corresponding character from an ASCII value.