Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » String FunctionsRSS Feeds

CHAR Function

Posted By: Sarita Patel     Category: SQL Server     Views: 3177

This article describes about CHAR function and it's use in sql server with examples.

CHAR function is used to convert an integer value to it's equivalent character.

It is also used to insert control characters into strings. Below table specifies control character and it's value.

Control Character

Value

Tab

CHAR(9)

Line Feed

CHAR(10)

Carriage return

CHAR(13)




Syntax of CHAR Function : 

CHAR ( integer_expression )

integer_expression is an integer from 0 through 255. If integer_expression is not in specified range than it returns NULL.

Return type of CHAR function is char type.   



Examples of CHAR Function : 

Example 1 : Use of CHAR function in select clause

SELECT CHAR(83)  

Output

Above example displays the use of CHAR function to display character based on ascii value.



Example 2 : Use of  CHAR function in where clause and nesting string functions

SELECT ContactName, CompanyName 
FROM   Customers
WHERE  CHAR(ASCII(ContactName)) = CHAR(ASCII(CompanyName))

Output
ContactName         CompanyName
Ana Trujillo            Ana Trujillo Emparedados y helados
Antonio Moreno     Antonio Moreno Taquería

Above example displays all customers, where first character of contact name and company name is same. It also shows how can we nest string functions. 
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on CHAR Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of CHAR Function is from United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!