Skip to content

Latest commit

 

History

History
86 lines (69 loc) · 2.98 KB

File metadata and controls

86 lines (69 loc) · 2.98 KB
title COL_LENGTH (Transact-SQL) | Microsoft Docs
ms.custom
ms.date 07/24/2017
ms.prod sql-non-specified
ms.reviewer
ms.suite
ms.technology
database-engine
ms.tgt_pltfrm
ms.topic language-reference
f1_keywords
COL_LENGTH
COL_LENGTH_TSQL
dev_langs
TSQL
helpviewer_keywords
lengths [SQL Server], columns
COL_LENGTH function
column properties [SQL Server]
column length [SQL Server]
ms.assetid cf891206-c49f-40eb-858e-eefd2b638a33
caps.latest.revision 20
author BYHAM
ms.author rickbyh
manager jhubbard

COL_LENGTH (Transact-SQL)

[!INCLUDEtsql-appliesto-ss2008-asdb-xxxx-xxx_md]

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

Topic link icon Transact-SQL Syntax Conventions

Syntax

COL_LENGTH ( 'table' , 'column' )   

Arguments

' 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.

Return type

smallint

Exceptions

Returns NULL on error or if a caller does not have permission to view the object.

In [!INCLUDEssNoVersion], 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.

Remarks

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

Examples

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;  

[!INCLUDEssResult]

VarChar     NVarChar  
40          80  

See also

Expressions (Transact-SQL)
Metadata Functions (Transact-SQL)
COL_NAME (Transact-SQL)
COLUMNPROPERTY (Transact-SQL)