len / datalength - Jean-Nicolas BERGER

08-May-08 03:00:20
Hello,
Could someone explain those results, I don't understand the second one
regarding the others ...
Thx.
JN.

select len(0x4000),datalength(0x4000)
-- Result : 2 - 2
select len(0x4020),datalength(0x4020)
-- Result : 1 - 2
select len(0x4021),datalength(0x4021)
-- Result : 2 - 2
button
 
 

len / datalength - Russell Fields

08-May-08 03:21:38
Jean-Nicolas,

From the BOL definition of LEN:  Returns the number of characters, instead
of the number of bytes, of the given string expression, *** excluding
trailing blanks.***

Since 0x20 is a blank, the second selection for LEN(0x4020) only counts the
1 character 0x40.

RLF
button
 

len / datalength - Tom Cooper

08-May-08 03:24:18
Len() returns the number of characters, excluding any trailing blanks.
Since 0x20 is a blank, the value of Len(0x4020) is 1.  But DataLength()
returns the number of bytes including any trailing blanks.

Tom
button
 

len / datalength - SQL Menace

09-May-08 07:50:51
Run this for fun

Select LEN(' ') As LengthVarChar,
LEN(N' ') As LengthNVarChar,
DATALENGTH(' ') As DataLengthVarChar,
DATALENGTH(N' ') As DataLengthNVarChar


Denis The SQL Menace
http://sqlservercode.blogspot.com
http://sqlblog.com/blogs/denis_gobo/default.aspx



On May 8, 3:00=A0pm, "Jean-Nicolas BERGER" <j-n.enlevezmoi.ber...@club-
button
 
Disappearing Carriage Returns