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.
    SELECT ASCII('A') 
    SELECT ASCII('Z') 


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

    DECLARE @Start int 
    set @Start=65 
    while(@Start<=90) 
    begin 
    print char(@Start) 
    set @Start=@Start+1 
    end 


To find the ASCII values of characters from a to z, we can use this query.
    SELECT ASCII('a') 
     
    SELECT ASCII('z') 
     
    DECLARE @Start int 
    set @Start=97 
    while(@Start<=122) 
    begin 
    print char(@Start) 
    set @Start=@Start+1 
    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.
    SELECT ASCII(9) 
     
    SELECT ASCII(0) 
     
    DECLARE @Start int 
    set @Start=48 
    while(@Start<=57) 
    begin 
    print char(@Start) 
    set @Start=@Start+1 
    end

HostForLIFE.eu SQL Server 2016 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.