none
Calling user defined function from stored procedure RRS feed

  • Question

  • When i call user defined function from stored procedure, i am getting an error.

     

    [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'dbo.MyFunction'.

     

    why this error is happening?.

     

    i am calling this way...    dbo.MyFunction(param1,param2)

    Monday, July 30, 2007 6:45 PM

Answers

  • I had the same problem due to calling the function incorectly:
    what I had was
      Select ... from [dbo].[MyFunction(@param)]
    I changed it to
      Select .... from [dbo].[MyFunction](@param)   << parens are outside the square bracket
    Monday, March 16, 2009 9:47 PM
  • First you need to identify whether your function is (1) a table function or (2) a scalar function.

    To fetch information from a table function:

    select
      col1,
      . . .
      colN
    from yourTableFunction

    To fetch information fro a scalar function:

    select
      col1,
      . . .
      dbo.ScalarFunction(arg1, . . ., argN)

    or perhaps

    set @someVariable = dbo.ScalarFunction(. . .)


    Kent Waldrop Mr09
    Monday, March 16, 2009 10:02 PM

All replies

  • Can you give the full statement?  This still does not look like enough information.

    Monday, July 30, 2007 7:09 PM
    Moderator
  • My first guess would be that your funciton is not residing in the same database as the stored procedure.
    Monday, July 30, 2007 7:16 PM
  • I had the same problem due to calling the function incorectly:
    what I had was
      Select ... from [dbo].[MyFunction(@param)]
    I changed it to
      Select .... from [dbo].[MyFunction](@param)   << parens are outside the square bracket
    Monday, March 16, 2009 9:47 PM
  • First you need to identify whether your function is (1) a table function or (2) a scalar function.

    To fetch information from a table function:

    select
      col1,
      . . .
      colN
    from yourTableFunction

    To fetch information fro a scalar function:

    select
      col1,
      . . .
      dbo.ScalarFunction(arg1, . . ., argN)

    or perhaps

    set @someVariable = dbo.ScalarFunction(. . .)


    Kent Waldrop Mr09
    Monday, March 16, 2009 10:02 PM