 |
|
SQL Server Tips by Burleson |
Nchar
Nchar stores fixed length Unicode data. The data is padded with
spaces on the right as this example shows:
DECLARE @b nchar(10)
SET @b='abc'
select DATALENGTH(@b), LEN(@b)
SELECT @b
20 3
abc
Each Unicode character takes two bytes and DATALENGTH returns the
length in terms of bytes, therefore twenty. LEN returns the number
of characters and it should be three because 'abc' is only three
characters.
Note: For ASCII data types, LEN and DATALENGTH return the same
value, unless the data has trailing spaces, which are not counted.
This is an important detail that results in subtle bugs.
The above book excerpt is from:
Super SQL
Server Systems
Turbocharge Database Performance with C++ External Procedures
ISBN:
0-9761573-2-2
Joseph Gama, P. J. Naughter
http://www.rampant-books.com/book_2005_2_sql_server_external_procedures.htm |