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

Troubleshooting Guide: SQL Server Error 434 — Function Not Allowed in OUTPUT Clause

Why This Error Happens

Error 434 occurs because SQL Server’s OUTPUT clause has strict limitations on which functions can be referenced within it, primarily to preserve deterministic behavior during INSERT, UPDATE, DELETE, or MERGE operations. Non-deterministic functions (such as RAND(), NEWID() in certain contexts, or user-defined functions with side effects) and functions that access data outside the affected rows are explicitly blocked. This is not a bug or corruption issue — it is a T-SQL syntax and design restriction enforced by the query optimizer to prevent inconsistent or unpredictable output during row-level operations.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Function in the Query

  • Open the failing query in SSMS (SQL Server Management Studio) or Azure Data Studio and locate the exact OUTPUT clause referenced in the error message.
  • Check the function name provided in the %ls placeholder of the error text — this tells you precisely which function triggered the restriction.
  • Common culprits include scalar user-defined functions (UDFs), ranking functions, and aggregate functions used directly inside OUTPUT.

Step 2: Rewrite the Query to Move the Function Outside OUTPUT

  • Modify the OUTPUT clause to only reference inserted.* and deleted.* columns, without calling functions directly.
  • Capture the raw output into a temporary table or table variable first:
  DECLARE @OutputTable TABLE (ID INT, OldValue NVARCHAR(100));

  UPDATE YourTable
  SET Column1 = 'NewValue'
  OUTPUT deleted.ID, deleted.Column1 INTO @OutputTable
  WHERE Condition = 1;
  • Apply the function (e.g., dbo.YourFunction()) in a separate SELECT statement that queries from @OutputTable afterward.

Step 3: Validate Compatibility Level and Query Logic

  • Confirm the database compatibility level is correctly set for SQL Server 2025 by running:
  SELECT name, compatibility_level FROM sys.databases WHERE name = 'YourDatabaseName';
  • If compatibility level is outdated (e.g., inherited from a migrated SQL Server 2016/2019 database), update it:
  ALTER DATABASE YourDatabaseName SET COMPATIBILITY_LEVEL = 170;
  • Re-run the corrected query to confirm the function restriction no longer triggers Error 434.

Step 4: Check for Nested or Indirect Function Calls

  • Inspect any views, computed columns, or triggers that may indirectly invoke restricted functions during the OUTPUT operation.
  • Use sys.sql_modules to search for hidden function references:
  SELECT definition FROM sys.sql_modules 
  WHERE definition LIKE '%YourFunctionName%';
  • Refactor any triggers or computed columns so restricted functions are evaluated outside the DML statement’s execution scope.

Alternative or Verification Steps

  • Run the corrected query in a test environment and confirm no Error 434 appears in the SQL Server Error Log (viewable via SSMS > Management > SQL Server Logs) or Windows Event Viewer under Applications and Services Logs > MSSQLSERVER.
  • As an alternative, wrap the entire operation in a stored procedure that performs the DML with a simplified OUTPUT clause, then applies post-processing logic (including the restricted function) in a subsequent step within the same procedure.