Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

CHAR() function in SQL Server

  • Last Updated : 28 Dec, 2020

CHAR() :
This function helps to convert an int ASCII code to character value i.e if the user pass an integer as an argument, the CHAR() function interpret the integer value and returns its corresponding character value.

Syntax :


Parameters :
This function accepts only one argument.

  • integer_value –
    Any integer value ranging from 0 to 255.

Returns :

  • The function will return the character value that corresponds to the given integer code.
  • The function will return NULL if the integer value exceeds the given range.

Applicable to following versions :

  • SQL Server 2017
  • SQL Server 2016
  • SQL Server 2014
  • SQL Server 2012
  • SQL Server 2008 R2
  • SQL Server 2008
  • SQL Server 2005

Example-1 :
Basic usage of CHAR() function, the function will return ‘P’ and ‘D’.

CHAR(80) AS 'Character1',
CHAR(100) AS 'Character2';

Output :


Example-2 :
If the range of integer values is exceeded in CHAR() function, then the function will return NULL.

AS 'Outcome';

Output :


Example-3 :
How to control Characters in CHAR() function, we use strings and CHAR() function between them,

SELECT 'Vansh' + CHAR(13) + '' 
AS 'Name_Email';

Output :



Example-4 :
If the user passes two arguments in CHAR() function, the function will return an error.

SELECT CHAR(91, 200) 
AS 'Outcome';

Output :

The char function requires 1 argument(s)
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!