UNICODE (Transact-SQL)

Gibt laut Definition des Unicode-Standards eine ganze Zahl für das erste Zeichen des Eingabeausdrucks zurück.

Syntax

UNICODE ( 'ncharacter_expression' )

Argumente

'ncharacter_expression'

Ein Ausdruck vom Datentyp nchar oder nvarchar.

Rückgabetypen

int

Beispiele

A. Verwenden von UNICODE und der NCHAR-Funktion

Im folgenden Beispiel werden die Funktionen UNICODE und NCHAR zur Ausgabe des UNICODE-Wertes des ersten Zeichens der Zeichenfolge Åkergatan 24 sowie zur Ausgabe des tatsächlichen ersten Zeichens, und zwar Å, verwendet.

DECLARE @nstring nchar(12)
SET @nstring = N'Åkergatan 24'
SELECT UNICODE(@nstring), NCHAR(UNICODE(@nstring))

Dies ist das Resultset. 

----------- - 
197         Å

B. Verwenden von SUBSTRING, UNICODE und CONVERT

Im folgenden Beispiel werden die Funktionen SUBSTRING, UNICODE und CONVERT zur Ausgabe der Zeichennummer, des Unicode-Zeichens und des UNICODE-Wertes für jedes Zeichen in der ZeichenfolgeÅkergatan 24 verwendet.

-- The @position variable holds the position of the character currently
-- being processed. The @nstring variable is the Unicode character 
-- string to process.
DECLARE @position int, @nstring nchar(12)
-- Initialize the current position variable to the first character in 
-- the string.
SET @position = 1
-- Initialize the character string variable to the string to process. 
-- Notice that there is an N before the start of the string, which 
-- indicates that the data following the N is Unicode data.
SET @nstring = N'Åkergatan 24'
-- Print the character number of the position of the string you are at, 
-- the actual Unicode character you are processing, and the UNICODE 
-- value for this particular character.
PRINT 'Character #' + ' ' + 'Unicode Character' + ' ' + 'UNICODE Value'
WHILE @position <= DATALENGTH(@nstring)
-- While these are still characters in the character string,
   BEGIN
   SELECT @position, 
      CONVERT(char(17), SUBSTRING(@nstring, @position, 1)),
      UNICODE(SUBSTRING(@nstring, @position, 1))
   SELECT @position = @position + 1
   END

Dies ist das Resultset. 

Character # Unicode Character UNICODE Value
                                          
----------- ----------------- ----------- 
1           Å                 197         
                                          
----------- ----------------- ----------- 
2           k                 107         
                                          
----------- ----------------- ----------- 
3           e                 101         
                                          
----------- ----------------- ----------- 
4           r                 114         
                                          
----------- ----------------- ----------- 
5           g                 103         
                                          
----------- ----------------- ----------- 
6           a                 97          
                                          
----------- ----------------- ----------- 
7           t                 116         
                                          
----------- ----------------- ----------- 
8           a                 97          
                                          
----------- ----------------- ----------- 
9           n                 110         
                                          
----------- ----------------- ----------- 
10                            32          
                                          
----------- ----------------- ----------- 
11          2                 50          
                                          
----------- ----------------- ----------- 
12          4                 52

Siehe auch

Verweis

Datentypen (Transact-SQL)
NCHAR (Transact-SQL)
Zeichenfolgenfunktionen (Transact-SQL)

Andere Ressourcen

Arbeiten mit Unicode-Daten

Hilfe und Informationen

Informationsquellen für SQL Server 2005