ASCII (Transact-SQL)

Restituisce il codice ASCII corrispondente al primo carattere a sinistra in una stringa di caratteri.

Icona di collegamento a un argomentoConvenzioni della sintassi Transact-SQL

Sintassi

ASCII ( character_expression )

Argomenti

  • character_expression
    Espressione di tipo char o varchar.

Tipi restituiti

int

Esempi

Nell'esempio seguente, che presuppone l'utilizzo del set di caratteri ASCII, viene restituito il valore ASCII e il carattere CHAR per ogni carattere della stringa Du monde entier.

SET TEXTSIZE 0
SET NOCOUNT ON
-- Create the variables for the current character string position 
-- and for the character string.
DECLARE @position int, @string char(15)
-- Initialize the variables.
SET @position = 1
SET @string = 'Du monde entier'
WHILE @position <= DATALENGTH(@string)
   BEGIN
   SELECT ASCII(SUBSTRING(@string, @position, 1)),
      CHAR(ASCII(SUBSTRING(@string, @position, 1)))
    SET @position = @position + 1
   END
SET NOCOUNT OFF
GO

Set di risultati:

----------- - 
68          D 
              
----------- - 
117         u 
              
----------- - 
32            
              
----------- - 
109         m 
              
----------- - 
111         o 
              
----------- - 
110         n 
              
----------- - 
100         d 
              
----------- - 
101         e 
              
----------- - 
32            
              
----------- - 
101         e 
              
----------- - 
110         n 
              
----------- - 
116         t 
              
----------- - 
105         i 
              
----------- - 
101         e 
              
----------- - 
114         r