Using DATALENGTH sees each character in an NVARCHAR string as two bytes.DECLARE @str NVARCHAR(50) = 'abcd'SELECT DATALENGTH(@str) -- 8 is returnedThis is because NVARCHAR's store the characters as double-byte unicode characters (UCS-2). Use VARCHAR if you want to store regular string data.For the trimming behaviour of LEN, see the comments at the LEN article: http://msdn.microsoft.com/en-us/library/ms190329.aspx
↧