Original: SQL datalength and Len distinguished usage
Len (string_expression) parameter: The string to be evaluated
Len () function
The Len function returns the length of the value in the Text field.
SQL Len () syntax
Select Len (column_name) from table_name
We want to get the length of the value in the City column.
We use the following SQL statement:
Select Len (city) as lengthofaddress from persons
Returns the number of characters in the specified string expression that does not contain trailing spaces.
If the data type of expression is varchar (max), nvarchar (max), or varbinary (max), it is bigint; otherwise, int.
The ntext field cannot be evaluated
DATALENGTH (expression) parameter: An expression of any data type
Grammar
Datalength (Expre (www.111cn.net) ssion)
Parameters
Expression
An expression of any type.
return type
Int
Use ADVENTUREWORKS2008R2;
Go
Select length = datalength (name), name
From Production.Product
Order BY name;
Go
Returns the number of bytes used to represent any expression.
If the data type of expression is varchar (max), nvarchar (max), or varbinary (max) data type, bigint is returned, otherwise int is returned.
For varchar, varbinary, text, image, nvarchar, and ntext data types, datalength is especially useful because these data types can store variable-length data. Www.111cn.net
The result of NULL datalength is null.
From:http://www.111cn.net/database/mssqlserver/37823.htm
SQL datalength and Len distinguish usage