ASCII Values Of Alphabets And Numbers In SQL Server

Introduction

To find the ASCII value of an alphabet or a number, we can use ASCII function in SQL Server. We will see how to get the ASCII value of numbers from 0-9 and uppercase and lowercase alphabets.

What is ASCII?

ASCII (American Standard Code for Information Interchange) is the most common format for text files in computers and on the internet. In an ASCII file, each alphabetic, numeric, or special character is represented with a 7-bit binary number (a string of seven 0s or 1s). There can be 128 possible characters defined. It serves as a character encoding standard for modern computers.

Syntax

ASCII ( ‘character_expression’ )

ASCII value of capital A is 65 and Z 90.

  1. SELECT ASCII('A')  
  2.   
  3. SELECT ASCII('Z')  

To find the ASCII values of alphabets from A to Z, use this code.

  1. DECLARE @Start int  
  2. set @Start=65  
  3. while(@Start<=90)  
  4. begin  
  5. print char(@Start)  
  6. set @Start=@Start+1  
  7. end  
ASCII Values Of Alphabets And Number In SQL Server

To find the ASCII values of characters from a to z, we can use this query.

  1. SELECT ASCII('a')  
  2.   
  3. SELECT ASCII('z')  
  4.   
  5. DECLARE @Start int  
  6. set @Start=97  
  7. while(@Start<=122)  
  8. begin  
  9. print char(@Start)  
  10. set @Start=@Start+1  
  11. end  
ASCII Values Of Alphabets And Number In SQL Server

To find the ASCII value of numbers from 0 to 9, we can use this query.

  1. SELECT ASCII(9)  
  2.   
  3. SELECT ASCII(0)  
  4.   
  5. DECLARE @Start int  
  6. set @Start=48  
  7. while(@Start<=57)  
  8. begin  
  9. print char(@Start)  
  10. set @Start=@Start+1  
  11. end  
ASCII Values Of Alphabets And Number In SQL Server