Troubleshooting Guide: SQL Server Error 10753 — “The function ‘%.*ls’ must have an OVER clause”
Why This Error Happens
This error occurs because certain window (ranking, aggregate, or analytic) functions such as RANK(), DENSE_RANK(), NTILE(), ROW_NUMBER(), LAG(), or LEAD() are syntactically required to be used with an OVER clause in Transact-SQL. The root cause is almost always a query authoring mistake where a developer calls one of these functions like a standard scalar function without specifying the partitioning or ordering logic via OVER (...). This is not a server configuration, permissions, or port issue — it is a T-SQL syntax validation error raised by the Query Optimizer/Parser in SQL Server 2025 during compilation.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Query
- Capture the exact failing statement from the application log, SSMS error pane, or SQL Server Error Log (
Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOGon Windows Server 2025). - Note the specific function name inserted into the
%.*lsplaceholder in the error message (e.g.,RANK,ROW_NUMBER,LAG). - Reproduce the issue in SQL Server Management Studio (SSMS) connected to the SQL Server 2025 instance to confirm the exact line number.
Step 2: Add the Required OVER Clause
- Rewrite the function call to include a valid
OVERclause with at least a basic ordering definition. - Example fix for
ROW_NUMBER:
SELECT ROW_NUMBER() OVER (ORDER BY OrderDate) AS RowNum
FROM Sales.Orders;
- Example fix for
RANKwith partitioning:
SELECT RANK() OVER (PARTITION BY CustomerID ORDER BY OrderDate DESC) AS SalesRank
FROM Sales.Orders;
- Ensure the
ORDER BYinsideOVER()references a valid column or expression present in the result set.
Step 3: Validate Compatibility Level and Syntax Support
- Confirm the database compatibility level supports the window function syntax being used:
SELECT name, compatibility_level
FROM sys.databases
WHERE name = 'YourDatabaseName';
- If compatibility level is below 130 (SQL Server 2016), update it to leverage full window function support in SQL Server 2025:
ALTER DATABASE YourDatabaseName SET COMPATIBILITY_LEVEL = 170;
- Re-run the corrected query to confirm the parser no longer raises Error 10753.
Step 4: Audit Stored Procedures and Views for Similar Patterns
- Search all stored procedures, functions, and views for other instances of ranking/analytic functions missing an
OVERclause. - Use the following query to locate potentially affected objects:
SELECT OBJECT_NAME(object_id) AS ObjectName, definition
FROM sys.sql_modules
WHERE definition LIKE '%RANK(%'
OR definition LIKE '%ROW_NUMBER(%'
OR definition LIKE '%NTILE(%'
OR definition LIKE '%LAG(%'
OR definition LIKE '%LEAD(%';
- Manually inspect each result and add the required
OVERclause where missing.
Alternative or Verification Steps
- After applying the fix, execute the corrected query/procedure in SSMS or via
sqlcmdand confirm it compiles and returns results without Error 10753. - If the error persists, check for cached or stale execution plans by running
DBCC FREEPROCCACHE(in a non-production environment first) to force recompilation of the corrected query.