Transact-SQL Reference


SQL Server 2008 Books Online (October 2009)
LEN (Transact-SQL)

Returns the number of characters of the specified string expression, excluding trailing blanks.

ms190329.note(en-us,SQL.100).gifNote:
To return the number of bytes used to represent an expression, use the DATALENGTH function.

Topic link icon Transact-SQL Syntax Conventions

Syntax

LEN ( string_expression )
Arguments

string_expression

Is the string expression to be evaluated. string_expression can be a constant, variable, or column of either character or binary data.

Return Types

bigint if expression is of the varchar(max), nvarchar(max) or varbinary(max) data types; otherwise, int.

Examples

The following example selects the number of characters and the data in FirstName for people located in Australia.

USE AdventureWorks;
GO
SELECT LEN(FirstName) AS Length, FirstName, LastName 
FROM Sales.vIndividualCustomer
WHERE CountryRegionName = 'Australia';
GO
See Also

Reference

Data Types (Transact-SQL)
String Functions (Transact-SQL)
DATALENGTH (Transact-SQL)
LEFT (Transact-SQL)
RIGHT (Transact-SQL)

Help and Information

Getting SQL Server 2008 Assistance
Tags :


Page view tracker