none
Error while creating inline function - CREATE FUNCTION failed because a column name is not specified for column 1.

    Question

  • Hi,

     

    I am trying to create a inline function which is listed below.

     

    USE [Northwind]

    SET ANSI_NULLS ON

    GO

    CREATE FUNCTION newIdentity()

    RETURNS TABLE

    AS

    RETURN

    (SELECT ident_current('orders'))

    GO

     

    while executing this function in sql server 2005 my get this error

    CREATE FUNCTION failed because a column name is not specified for column 1.

     

    Pleae help me to fix this error

     

    thanks

    Purnima

    Tuesday, April 03, 2007 2:43 PM

All replies

  •  

    Hi,

     

    I am trying to create a inline function which is listed below.

     

    USE [Northwind]

    SET ANSI_NULLS ON

    GO

    CREATE FUNCTION newIdentity()

    RETURNS TABLE

    AS

    RETURN

    (SELECT ident_current('orders'))

    GO

     

    while executing this function in sql server 2005 my get this error

    CREATE FUNCTION failed because a column name is not specified for column 1.

     

    Pleae help me to fix this error

     

    thanks

    Purnima

     

    Tuesday, April 03, 2007 2:41 PM
  • You have to specify an alias for the columns in the select statement. Change the query to somthing like this:

     

    Code Snippet

     

    SELECT ident_current('orders') AS 'ID'

     

    I hope this answers your question.

     

    Best regards,

    Sami Samir

     

    Tuesday, April 03, 2007 3:41 PM
  • Thats easy:

     

    Code Snippet

    USE [Northwind]

    SET ANSI_NULLS ON

    GO

    CREATE FUNCTION newIdentity()

    RETURNS TABLE

    AS

    RETURN

    (SELECT ident_current('orders') AS Newidentity)

    GO

     

     


    Jens K. Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---

    Tuesday, April 03, 2007 5:30 PM