Applies To: SQL Server 2014, SQL Server 2016 Preview
Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).
Returns the defined length, in bytes, of a column.
Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database.
Returns NULL on error or if a caller does not have permission to view the object.
In SQL Server, a user can only view the metadata of securables that the user owns or on which the user has been granted permission. This means that metadata-emitting, built-in functions such as COL_LENGTH may return NULL if the user does not have any permission on the object. For more information, see Metadata Visibility Configuration.
The following example shows the return values for a column of type varchar(40) and a column of type nvarchar(40).
USE AdventureWorks2012; GO CREATE TABLE t1(c1 varchar(40), c2 nvarchar(40) ); GO SELECT COL_LENGTH('t1','c1')AS 'VarChar', COL_LENGTH('t1','c2')AS 'NVarChar'; GO DROP TABLE t1;
Here is the result set.
VarChar NVarChar 40 80