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 there any good way to build a comma-separated list in SQL Server?
  • Generate unique random numbers using SQL
  • C# - SQLClient - Simplest INSERT
  • Create trigger to insert a column value into other column of same table SQL Server 2005
  • SQL Selecting multiple sums?
  • Script that provides the row counts and table names
  • 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

  • Sequential Group By in sql server
  • How do I Sort a varchar with numbers and letters without a specific format?
  • Composite Primary Key On Table Variable In Stored Procedure
  • How to avoid duplicates in INSERT INTO SELECT query in SQL Server?
  • Use SQL to filter the results of a stored procedure
  • Transpose rows to columns based on ID column
  • 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.