Export (0) Print
Expand All
Expand Minimize
1 out of 1 rated this helpful - Rate this topic

COL_LENGTH (Transact-SQL)

Returns the defined length, in bytes, of a column.

Topic link iconTransact-SQL Syntax Conventions


COL_LENGTH ('table','column')
'table'

Is the name of the table for which to determine column length information. table is an expression of type nvarchar.

'column'

Is the name of the column for which to determine length. column is an expression of type nvarchar.

smallint

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 and Troubleshooting Metadata Visibility.

For columns of type varchar declared with the max specifier (varchar(max)), COL_LENGTH returns the value –1.

The following example shows the return values for a column of type varchar(40) and a column of type nvarchar(40).

USE AdventureWorks;
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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.