CHAR (Transact-sql)

Dönüştüren bir intbir karakterin ASCII kodu.

Konu bağlantısı simgesi Transact-SQL Sözdizim Kuralları

Sözdizimi

CHAR ( integer_expression )

Bağımsız değişkenler

  • integer_expression
    0 ile 255 arasında bir tamsayıdır. null döndürülen tamsayı deyim bu aralıkta değilse.

Dönüş Türleri

char(1)

Açıklamalar

char karakter dizeleri denetim karakterleri eklemek için kullanılabilir. Aşağıdaki tablo, bazı sık kullanılan denetim karakterleri gösterir.

Denetim karakteri

Değer

Sekme

char(9)

Satır besleme

char(10)

Satır başı

char(13)

Örnekler

A.Bir dizeden ASCII değerleri yazdırmak için ASCII ve char kullanma

Aşağıdaki örnek ASCII değeri ve dizedeki her karakter için karakter yazdırır New Moon.

SET TEXTSIZE 0
-- Create variables for the character string and for the current 
-- position in the string.
DECLARE @position int, @string char(8)
-- Initialize the current position and the string variables.
SET @position = 1
SET @string = 'New Moon'
WHILE @position <= DATALENGTH(@string)
   BEGIN
   SELECT ASCII(SUBSTRING(@string, @position, 1)), 
      CHAR(ASCII(SUBSTRING(@string, @position, 1)))
   SET @position = @position + 1
   END
GO

SET TEXTSIZE 0
-- Create variables for the character string and for the current 
-- position in the string.
DECLARE @position int, @string char(8)
-- Initialize the current position and the string variables.
SET @position = 1
SET @string = 'New Moon'
WHILE @position <= DATALENGTH(@string)
   BEGIN
   SELECT ASCII(SUBSTRING(@string, @position, 1)), 
      CHAR(ASCII(SUBSTRING(@string, @position, 1)))
   SET @position = @position + 1
   END
GO

Sonuç kümesi buradadır.

----------- -

78 N

----------- -

101 e

----------- -

119 w

----------- -

32

----------- -

77 M

----------- -

111 o

----------- -

111 o

----------- -

110 n

----------- -

B.char denetim karakteri eklemek için kullanma

Aşağıdaki örnek CHAR(13)sonuçları metin döndürülmediğinde ayrı satırlara bir çalışanın adını ve e-posta adresi yazdırmak için.

USE AdventureWorks2012;
GO
SELECT p.FirstName + ' ' + p.LastName, + CHAR(13)  + pe.EmailAddress 
FROM Person.Person p JOIN Person.EmailAddress pe
ON p.BusinessEntityID = pe.BusinessEntityID
AND p.BusinessEntityID = 1;
GO

USE AdventureWorks2012;
GO
SELECT p.FirstName + ' ' + p.LastName, + CHAR(13)  + pe.EmailAddress 
FROM Person.Person p JOIN Person.EmailAddress pe
ON p.BusinessEntityID = pe.BusinessEntityID
AND p.BusinessEntityID = 1;
GO

Sonuç kümesi buradadır.

Ken Sanchez

ken0@adventure-works.com

(1 row(s) affected)

Ayrıca bkz.

Başvuru

(Bitiştirme dize) + (Transact-sql)

Dize işlevler (Transact-sql)