Condividi tramite


ASCII (Transact-SQL)

Restituisce il codice ASCII del carattere più a sinistra in un'espressione di caratteri.

Si applica a: SQL Server (SQL Server 2008 tramite versione corrente), Database SQL di Windows Azure (versione iniziale tramite versione corrente).

Icona di collegamento a un argomento Convenzioni 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

Vedere anche

Riferimento

Funzioni per i valori stringa (Transact-SQL)