Link to home
Start Free TrialLog in
Avatar of JCM0165
JCM0165

asked on

SqlException 'Function name' is not a recognized built-in function name.

MS SQL 2005

This is a function within a stored procefure

      SET @FunctionText = N'SELECT @Achieved = ' + @Function + N'("' + cast(@Customer_ID as varchar(5)) + N'", "' + cast(@date as varchar(12)) + N'")'  ------
      EXEC sp_executesql @FunctionText, N'@Achieved int output ',@Achieved out

generates error

SqlException (0x80131904): 'F_SELECT_FITPOINT_ADHERENCE' is not a recognized built-in function name.

when I make it a 2-partname, I get the error

Cannot find either column "dbo" or the user-defined function or aggregate "dbo.Function_Name", or the name is ambiguous.
Avatar of Aneesh
Aneesh
Flag of Canada image

whenever you calls a User defined function, you need to mention the owner name  also, for example, if the owner of your function is 'dbo', then the function call shoulld be

dbo.F_SELECT_FITPOINT_ADHERENCE

Avatar of JCM0165
JCM0165

ASKER

anee,

when I make it a 2-partname, I get the error

Cannot find either column "dbo" or the user-defined function or aggregate "dbo.Function_Name", or the name is ambiguous.
>I make it a 2-partname, I get the error
How did you do that ? did you modify the Query ,if so paste it here ?

aneesh
Avatar of JCM0165

ASKER

Annesh, here

SET @Function =
      (
      SELECT   TOP (1) Function_
      FROM         FitPoint_Categories
      WHERE     (Order_ = @Order) AND (Deleted <> 1) AND FPQ_ID = @FPQ_ID
      ORDER BY FPC_ID DESC
      )

      SET @FunctionText = N'SELECT @Achieved = ' + @Function + N'("' + cast(@Customer_ID as varchar(5)) + N'", "' + cast(@date as varchar(12)) + N'")'  ------
      EXEC sp_executesql @FunctionText, N'@Achieved int output ',@Achieved out

I haven't seen where you added that 'dbo', Okay, i am going to add that owner of that function

SELECT   TOP 1 @Function = Function_
FROM         FitPoint_Categories
WHERE     (Order_ = @Order) AND (Deleted <> 1) AND FPQ_ID = @FPQ_ID
ORDER BY FPC_ID DESC

SELECT @Function = ROUTINE_SCHEMA+'.' +@Function
 FROM information_Schema.Routines
WHERE ROUTINE_NAME  = @FunctionName

SET @FunctionText = N'SELECT @Achieved = dbo.' + @Function + N'("' + cast(@Customer_ID as varchar(5)) + N'", "' + cast(@date as varchar(12)) + N'")'  ------
EXEC sp_executesql @FunctionText, N'@Achieved int output ',@Achieved out
Avatar of JCM0165

ASKER



got
Must declare the scalar variable "@FunctionName".
Avatar of JCM0165

ASKER

used @Function instead of @FunctionName

got
Cannot find either column "fasterfitness" or the user-defined function or aggregate "fasterfitness.F_SELECT_FITPOINT_ADHERENCE", or the name is ambiguous.
ooops,  change '@FunctionName'  to '@Function'
SELECT   TOP 1 @Function = Function_
FROM         FitPoint_Categories
WHERE     (Order_ = @Order) AND (Deleted <> 1) AND FPQ_ID = @FPQ_ID
ORDER BY FPC_ID DESC

SELECT @Function = ROUTINE_SCHEMA+'.' +@Function
 FROM information_Schema.Routines
WHERE ROUTINE_NAME  = @FunctionName

SET @FunctionText = N'SELECT @Achieved = dbo.' + @Function + N'("' + cast(@Customer_ID as varchar(5)) + N'", "' + cast(@date as varchar(12)) + N'")'  ------
print @functionName
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial