SQL Server – ASCII function with example

ASCII function

ASCII will return ASCII value of left most character of the string or character expression.

Syntax:

SELECT ASCII(string or character_expression)

It take input parameter as string or  single character value and returns integer as result.

Example

Here we will use ASCII function to find out the ASCII code value of Alphabet A, B and C. Also we will take string as input parameter to display the ASCII value of left most  character of String.

SET NOCOUNT ON
SELECT ASCII(‘A’) as ‘ASCII code value of A’
SELECT ASCII(‘B’) as ‘ASCII code value of B’
SELECT ASCII(‘C’) as ‘ASCII code value of C’
Result
ASCII code value of A
———————
65
ASCII code value of B
———————
66
ASCII code value of C
———————
67
SELECT ASCII(‘Hello World’) AS ‘ASCII code value Of left most character’
Result
ASCII code value Of left most character
—————————————
72

Leave a Reply

  

  

  


4 − = 3