||SQL Server Tips by Gama and Naughter
Nchar stores fixed length Unicode
data. The data is padded with spaces on the right as this example
DECLARE @b nchar(10)
select DATALENGTH(@b), LEN(@b)
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:
Turbocharge Database Performance with C++ External Procedures
Joseph Gama, P. J. Naughter