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 name of a column from a specified corresponding table identification number and column identification number.
Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database, Azure SQL Data Warehouse Public Preview.
Returns NULL on error or if a caller does not have permission to view the object.
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 may return NULL if the user does not have any permission on the object. For more information, see Metadata Visibility Configuration.
The table_id and column_id parameters together produce a column name string.
For more information about obtaining table and column identification numbers, see OBJECT_ID (Transact-SQL).
The following example returns the name of the first column in the Employee table of the AdventureWorks2012 database.
USE AdventureWorks2012; GO SET NOCOUNT OFF; GO SELECT COL_NAME(OBJECT_ID('HumanResources.Employee'), 1) AS 'Column Name'; GO
Here is the result set.