Write for Us
Error Message:Msg 4514, Level 16, State 1, Procedure myfunction, Line 6CREATE FUNCTION failed because a column name is not specified for column %d.
Severity level:16.
Description:This error message appears when you try to create a user-defined function in which for at least one column no explicite name was specified or SQL Server wasn't able to deduct such a column name.
Consequences:The T-SQL statement can be parsed, but causes the error at runtime.
Resolution:Errors of the Severity Level 15 are generated by the user and are corrigible by the user. The statement cannot be executed this way. Each column in a table-valued user-defined function must have a unique name.
Versions:All versions of SQL Server.
Example(s):USE NorthwindIF OBJECT_ID ('dbo.myfunction') > 0 DROP FUNCTION dbo.myfunction;GOCREATE FUNCTION dbo.myfunction (@CustomerID nchar(5))RETURNS TABLEASRETURN ( SELECT *, 1 FROM Northwind.dbo.Orders WHERE CustomerID = @CustomerID);GOSELECT * FROM dbo.myfunction ('ALFKI');
Remarks:A single SELECT statement such as
SELECT CustomerID, COUNT(*) FROM Northwind.dbo.Orders WHERE CustomerID = @CustomerID GROUP BY CustomerID
works fine even with the missing column name for the COUNT(*) expression. In this case will SQL Server automatically assign a dummy name. However, this does not work for table-valued functions.