How to fix Error 4194 on Windows Server 2025 / Windows 11

Troubleshooting Guide: SQL Server Error 4194 – Invalid RANGE Window Frame Delimiter

Why This Error Happens

This error occurs when a T-SQL query uses a window function with a RANGE clause combined with offset-based frame delimiters (such as N PRECEDING or N FOLLOWING), which SQL Server does not support. SQL Server’s query optimizer strictly enforces that RANGE can only be paired with UNBOUNDED PRECEDING, UNBOUNDED FOLLOWING, or CURRENT ROW. This typically happens after migrating queries from another RDBMS (like PostgreSQL or Oracle) that permits more flexible RANGE syntax, or when a developer intends to use ROWS but mistakenly types RANGE instead.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Query

  • Capture the exact T-SQL statement from the application log or SQL Server error log located at C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG on Windows Server 2025.
  • Look for the OVER() clause in the query containing a RANGE BETWEEN definition.
  • Confirm the frame delimiter uses a numeric offset, e.g., RANGE BETWEEN 3 PRECEDING AND CURRENT ROW.

Step 2: Replace RANGE with ROWS (Recommended Fix)

  • In most cases, the intended logic works correctly if you simply switch the keyword from RANGE to ROWS.
  • Update the query syntax: change RANGE BETWEEN 3 PRECEDING AND CURRENT ROW to ROWS BETWEEN 3 PRECEDING AND CURRENT ROW.
  • Re-run the query in SQL Server Management Studio (SSMS) or Azure Data Studio to confirm the syntax error (4194) is resolved.
  • Note: ROWS operates on physical row counts, while RANGE operates on logical value ranges, so verify the business logic still matches your requirements.

Step 3: Adjust Logic if Logical Range Behavior is Required

  • If you specifically need value-based range logic (not physical row counts), restructure the query to use UNBOUNDED PRECEDING and CURRENT ROW instead of a numeric offset.
  • Example valid syntax: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.
  • If a sliding numeric range is mandatory, consider refactoring the query using a self-join or APPLY operator to manually simulate the boundary logic.

Step 4: Update ORM or Migration Scripts

  • If the query was auto-generated by an ORM (Entity Framework, Hibernate) or migrated from another database engine, check the source mapping templates.
  • Search your codebase or migration scripts for .Range( or equivalent builder methods and patch the template to force ROWS generation for SQL Server targets.

Alternative or Verification Steps

  • Run the corrected query directly in SSMS connected to your SQL Server 2025 instance; a successful execution with a result set (rather than Error 4194) confirms the fix.
  • If the error persists, verify the SQL Server Compatibility Level of the database (right-click Database → Properties → Options) is set to 170 (SQL Server 2025) to ensure the latest window function parser logic is being used.