| title | COL_NAME (Transact-SQL) | Microsoft Docs | ||||
|---|---|---|---|---|---|
| ms.custom | |||||
| ms.date | 07/24/2017 | ||||
| ms.prod | sql | ||||
| ms.prod_service | database-engine, sql-database, sql-data-warehouse, pdw | ||||
| ms.service | |||||
| ms.component | t-sql|functions | ||||
| ms.reviewer | |||||
| ms.suite | sql | ||||
| ms.technology |
|
||||
| ms.tgt_pltfrm | |||||
| ms.topic | language-reference | ||||
| f1_keywords |
|
||||
| dev_langs |
|
||||
| helpviewer_keywords |
|
||||
| ms.assetid | 214144ab-f2bc-4052-83cf-caf0a85c4cc6 | ||||
| caps.latest.revision | 28 | ||||
| author | edmacauley | ||||
| ms.author | edmaca | ||||
| manager | craigg | ||||
| ms.workload | On Demand | ||||
| monikerRange | >= aps-pdw-2016 || = azuresqldb-current || = azure-sqldw-latest || >= sql-server-2016 || = sqlallproducts-allversions |
[!INCLUDEtsql-appliesto-ss2008-all-md]
This function returns the name of a table column, based on the table identification number and column identification number values of that table column.
Transact-SQL Syntax Conventions
COL_NAME ( table_id , column_id ) table_id
The identification number of the table containing that column. The table_id argument has an int data type.
column_id
The identification number of the column. The column_id argument has an int data type.
sysname
Returns NULL on error, or if a caller does not have the correct 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_NAME might return NULL, if the user does not have correct permissions on the object. See Metadata Visibility Configuration for more information.
The table_id and column_id parameters together produce a column name string.
See OBJECT_ID (Transact-SQL) for more information about obtaining table and column identification numbers.
This example returns the name of the first column in a sample Employee table.
-- Uses AdventureWorks
SELECT COL_NAME(OBJECT_ID('dbo.FactResellerSales'), 1) AS FirstColumnName,
COL_NAME(OBJECT_ID('dbo.FactResellerSales'), 2) AS SecondColumnName; [!INCLUDEssResult]
ColumnName
------------
BusinessEntityID Expressions (Transact-SQL)
Metadata Functions (Transact-SQL)
COLUMNPROPERTY (Transact-SQL)
COL_LENGTH (Transact-SQL)