Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 327: Ambiguous Function Call Fixed

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server error 327 means the name you used in a function call matches more than one object that the engine could use, and it refuses to guess which one you meant. The message usually reads "The function call is ambiguous; both 'name' and 'name' are candidates" or "...both a user-defined function and a built-in function are candidates." It is a resolution problem, not a corruption problem: two or more functions share the same name, and SQL Server needs you to qualify the call with a schema or change which database or object context applies. Fixing it almost always means prefixing the call with the correct schema (for example dbo.MyFunction(...)) or qualifying the database, then re-testing the query. This guide walks through finding the competing objects, choosing the right one, and preventing the error from coming back.

What You'll Need

  • A login that can run the failing query, plus permission to view object metadata in the affected databases (membership in a role that can read sys.objects and sys.schemas, or similar).
  • A query window in SQL Server Management Studio, Azure Data Studio, or any client that can run T-SQL against the server.
  • The exact text of the failing statement, including any USE statement, connection context, and any default schema the executing login uses.
  • Access to change the calling code (stored procedure, view, function, report, ORM query) if the fix has to be applied there rather than in an ad-hoc window.

Step-by-Step

  1. Read the full error text. Error 327 is accompanied by the name it could not resolve, and sometimes by both candidate objects. Note the function name exactly as written, then note the database and schema context in which the statement ran (the database in the toolbar or connection, and the default schema of the login). This tells you where to search.
  2. Search for every object with that name across schemas. Run a query against the catalog views to list matches. Use SELECT s.name AS schema_name, o.name, o.type_desc FROM sys.objects o JOIN sys.schemas s ON s.schema_id = o.schema_id WHERE o.name = 'YourFunctionName'; in the database where the call is made. Run it in other databases on the same server too if the call crosses database boundaries, since resolution can reach objects in other schemas and, in some cases, other databases.
  3. Check for a built-in function with the same name. Error 327 also fires when a user-defined function shadows a system function and the call is unqualified, so SQL Server sees both a user function and a built-in as candidates. If your function name matches a built-in (for example something resembling DATEADD, CONVERT, FORMAT, or another system function), qualification with a schema is the standard solution.
  4. Identify the duplicate. If the search returns two or more user objects with the same name in different schemas, decide which one the query should use. If it returns one user object and a built-in, your function wins only if you qualify it as schema.FunctionName(...). Never rename a system function and never try to drop one.
  5. Qualify the call. Edit the statement to include the schema: SELECT dbo.MyFunction(Col) FROM dbo.MyTable; rather than SELECT MyFunction(Col) FROM dbo.MyTable;. If the object lives in another database, use the three-part name DbName.dbo.MyFunction(...). Three-part and four-part names are the unambiguous form; unqualified names are not.
  6. Re-run and verify. Execute the corrected statement. If the call was inside a stored procedure, view, or function, use ALTER to apply the change to that module's definition rather than just fixing your ad-hoc test. Remember that changing the module definition requires the appropriate permission on the object.
  7. Fix the call site, not just the symptom. Search your codebase, reports, jobs, and application layer for unqualified references to the name. A common pattern is a stored procedure that compiled fine until a second schema was added, at which point the procedure began failing at run time. Update every reference, then redeploy.
  8. Check the default schema of the executing login. If the login's default schema differs from what you assumed, name resolution shifts. You can see this in the login's properties or in the security catalog views; confirm which schema the unqualified name would resolve to before assuming qualification is unnecessary.
  9. Consider schema-binding and ownership chaining. In databases where objects are schema-bound, changes are restricted, so you may need to drop and recreate the binding rather than simply altering. Treat this as a planned change with a backup available, because dropping objects loses their permissions.
  10. Confirm the fix in the real environment. Run the application's actual query path, not just your test window, because the application may connect with a different login and default schema. If the error persists in the app but not in your window, the difference is almost always connection context or the unqualified name in a different code path.

Common Mistakes

  • Renaming or dropping the "wrong" function to make the error disappear. That breaks every other caller that relied on it. Qualify the call instead.
  • Assuming the error is a permissions issue. Error 327 is about name resolution; permissions produce different errors.
  • Fixing the query in one window and forgetting the stored procedure, job, or report that contains the original unqualified call.
  • Searching only the current schema. The competing object may sit in a different schema, and the catalog query in Step 2 must cover the whole database.
  • Changing the default schema of a login to "solve" it, which can silently redirect other unqualified references and cause new, harder-to-find problems.
  • Trying to reference a user function and a built-in with the same unqualified name and expecting SQL Server to prefer one. It will not; you must qualify.

Tips

  • Always schema-qualify function and table references in production code. It costs a few characters and removes a whole class of resolution errors.
  • Keep function names distinct from common built-in names to avoid accidental collisions.
  • When creating objects in a deployment script, be explicit about the schema rather than relying on the deployer's default schema.
  • Give functions in different schemas clearly different names where possible, so future maintainers do not have to decode which one is intended.
  • Test changes with the same login the application uses; developer logins often have different default schemas.
  • Version-control stored procedures and views so unqualified calls are easy to find and fix across all code paths.

Troubleshooting

If qualifying the call does not clear the error, confirm you qualified the same name the error reported, and check for case or whitespace differences between what you wrote and what exists. If the object is in another database, a three-part name may be blocked by cross-database permissions; test with a login that has access to both databases to isolate a permissions problem from a resolution problem.

If the error appears only at run time and not when you create or alter the procedure, the procedure was likely compiled against a context where the name was unique and later became ambiguous after another object was added. Recompile the procedure after qualifying the call. If you see a related error about deferred name resolution, check that every referenced object exists in the schema you expect.

If the error only occurs in the application, compare the connection string's initial catalog and the login's default schema with your test window. If a database is in a compatibility level that behaves differently, test in the target database rather than a copy. When a deployment introduced a new function or schema and the error started immediately, roll back or qualify the callers before continuing. Never drop objects to "reset" the database without a backup; dropping a function also drops its permissions and any bindings.

Frequently Asked Questions

What exactly does SQL Server error 327 mean?

It means the function name in your call matches more than one candidate object, so SQL Server cannot decide which one to use. It resolves the ambiguity by failing rather than picking one.

Why does the same query work in one database and fail in another?

Name resolution depends on the database and schema context plus the login's default schema. A function name that is unique in one database can be duplicated in another, or a built-in can be shadowed there.

Can I fix it by renaming the function?

You can, but every caller must be updated and it breaks compatibility for existing code. Qualifying the call with the schema is the safer, standard fix.

Does qualifying with the schema always solve the error?

Yes, in the normal case, because a schema-qualified name identifies one object. It does not help if permissions block access to that object, which is a separate error.

Why did the error suddenly appear after a deployment?

A new function or schema probably introduced a second object with the same name, making a previously unambiguous unqualified call ambiguous. Qualify the callers and redeploy.

Is error 327 related to a missing object?

No. A missing object produces a different error. Error 327 means the object exists in more than one place and the name was not specific enough.