SQL ASCII | SQL Server ASCII() Function With Example
SQL ASCII(): In this article, you will learn the SQL ASCII string function, and how to use the SQL Server function ASCII() to get the ASCII code of a character. this is mostly used SQL string function.
In the SQL Server, This function is used to find the ASCII value of a character.
Definition and Usage
The ASCII function returns the ASCII code value for the specific character. The ASCII function accepts a character expression and returns the ASCII code value of the leftmost character of the character expression.
SQL ASCII Synatx
The following shows the syntax of the SQL ASCII() function:
Parameter Values
Parameter | Description |
---|---|
input_string | Required. the input_string can be a literal character, a character string expression, or a column. furthermore, if the input_string has more than one character, then the function returns the ASCII code value of its leftmost character. |
SQL ASCII() Function Example:
Table Name:Customers
CustomerName | ContactName | Address | City | PostalCode | Country |
---|---|---|---|---|---|
Alfreds Futterkiste | Maria Anders | Obere Str. 57 | Berlin | 12209 | Germany |
Ana Trujillo Emparedados y helados | Ana Trujillo | Avda. de la Constitución 2222 | México D.F. | 5021 | Mexico |
Blauer See Delikatessen | Hanna Moos | Forsterstr. 57 | Mannheim | 68306 | Germany |
Antonio Moreno Taquería | Antonio Moreno | Mataderos 2312 | México D.F. | 5023 | Mexico |
Blondel père et fils | Frédérique Citeaux | 24, place Kléber | Strasbourg | 67000 | France |
Bs Beverages | Victoria Ashworth | Fauntleroy Circus | London | 87000 | UK |
Bottom-Dollar Marketse | Elizabeth Lincoln | 23 Tsawassen Blvd. | Tsawassen | 45300 | Canada |
Bon app | Laurence Lebihans | 12, rue des Bouchers | Marseille | 13008 | France |
Bólido Comidas preparadas | Martín Sommer | C/ Araquil, 67 | Madrid | 28023 | Spain |
Consolidated Holdings | Elizabeth Brown | Berkeley Gardens 12 Brewery | London | 98760 | UK |
Comércio Mineiro | Pedro Afonso | Av. dos Lusíadas, 23 | São Paulo | 5432 | Brazil |
Chop-suey Chinese | Yang Wang | Hauptstr. 29 | Bern | 3012 | Switzerland |
Centro comercial Moctezuma | Francisco Chang | Sierras de Granada 9993 | México D.F. | 5022 | Mexico |
Du monde entier | Janine Labrune | 67, rue des Cinquante Otages | Nantes | 44000 | France |
Drachenblut Delikatessend | Sven Ottlieb | Walserweg 21 | Aachen | 52066 | Germany |
Ernst Handel | Roland Mendel | Kirchgasse 6 | Graz | 8010 | Austria |
Eastern Connection | Ann Devon | 35 King George | London | 11036 | UK |
Franchi S.p.A. | Paolo Accorti | Via Monte Bianco 34 | Torino | 10100 | Italy |
Furia Bacalhau e Frutos do Mar | Lino Rodriguez | Jardim das rosas n. 32 | Lisboa | 1675 | Portugal |
France restauration | Carine Schmitt | 54, rue Royale | Nantes | 44000 | France |
Frankenversand | Peter Franken | Berliner Platz 43 | München | 80805 | Germany |
Folk och fä HB | Maria Larsson | Åkergatan 24 | Bräcke | 885634 | Sweden |
Folies gourmandes | Martine Rancé | 184, chaussée de Tournai | Lille | 59000 | France |
FISSA Fabrica Inter. Salchichas S.A. | Diego Roel | C/ Moralzarzal, 86 | Madrid | 28034 | Spain |
GROSELLA-Restaurante | Manuel Pereira | 5A Ave. Los Palos Grandes | Caracas | 1081 | Venezuela |
Great Lakes Food Market | Howard Snyder | 2732 Baker Blvd. | Eugene | 97403 | USA |
Gourmet Lanchonetes | André Fonseca | Av. Brasil, 442 | Campinas | 4876786 | Brazil |
Godos Cocina Típica | José Pedro Freyre | C/ Romero, 33 | Sevilla | 411256 | Spain |
Galería del gastrónomo | Eduardo Saavedra | Rambla de Cataluña, 23 | Barcelona | 8022 | Spain |
Hanari Carnes | Mario Pontes | Rua do Paço, 67 | Rio de Janeiro | 5454876 | Brazil |
SQL ASCII() Query
Return the ASCII value of the first character in “ContactName”:
1 2 |
SELECT ASCII(ContactName) AS NumCodeOfFirstChar FROM Customers; |
Therefore, let’s execute the query to return the output.
Conclusion:
In this tutorial, you have learned the SQL ASCII string function, and how to use the SQL Server ASCII function to get the ASCII code value of a character.