How to find ASCII code in sql server

ASCII means American Standard Code for Information Interchange.
This function is use to find the ASCII code value of the leftmost character in the string.

Syntax : ASCII(‘Character_expression’)

Character Expression – value can be char or varchar type.


Declare @str varchar(20)
Set @str = ‘ANIL’

declare @count int
Set @count = 1

while (@count <= len(@str))

select ‘Character’= substring(@str,@count,1),’ASCII Value’ = ASCII(substring(@str,@count,1))

set @count=@count+1

Leave a Reply




3 + = 7