Call a user defined function defined in schemaA from a view defined in SchemaB SQL Server

I am having a problem to call a function from my view. They are both in different schemas, so I have something like this:

View [SchemaA].[ViewName]
    WITH SCHEMABINDING
    AS
        SELECT DISTINCT
             [SchemaB].[functionName](value) as 'variable'
        FROM
            //Several selects with joins

The problem is that I am getting this error: “Cannot schema bind view ‘SchemaA.view’. ‘SchemaB.functionName’ is not schema bound.”

  • Is VARCHAR like totally 1990s?
  • Calculation of Two Cells According To Condition
  • Can it be better to create a cursor over data copied to a table variable instead of the actual table?
  • sql query to get record by multiple values
  • Hibernate mssql dialect
  • Converting ntext to varchar in SQL Server 2005
  • I have also tried to include the database name in the call to the function like this:

    [database].[SchemaB].[functionName]
    

    But it still didn’t work. However it returned a different error: “Cannot schema bind view ‘SchemaA.view’ because name ‘SchemaB.functionName’ is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.”

    Any idea about what I am doing wrong?

    Thanks

  • Modify Default value in SQL Server
  • Generate different random time in the given interval
  • SQL — Excluding Tuples
  • How to Add a column to a table the column values depends on another columns
  • Store into two tables with primary key simultaneously
  • update bases on sum
  • One Solution collect form web for “Call a user defined function defined in schemaA from a view defined in SchemaB SQL Server”

    Your function should be schema bound (WITH SCHEMABINDING):

    CREATE FUNCTION SchemaBinded(@INPUT INT)
    RETURNS INT WITH SCHEMABINDING
    BEGIN
    RETURN @INPUT * 2 + 50
    END
    GO
    
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.