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

Why This Error Happens

Error 10720 occurs because SQL Server does not allow an OUTPUT INTO clause to be used inside an INSERT statement that is itself nested within another INSERT...EXEC or a derived table/CTE acting as an insert source. This is a T-SQL language limitation rather than a configuration or permissions issue—the query optimizer cannot reconcile capturing output rows into a table variable or temp table while the INSERT operation is simultaneously being consumed by an outer statement. It typically surfaces when developers try to chain multiple data modification operations together (e.g., using INSERT INTO ... OUTPUT INTO ... as a source for another INSERT).

Step-by-Step Resolution Guide

Step 1: Identify the Nested Statement Causing the Conflict

  • Review the query plan or script that triggered Error 10720 in SQL Server Management Studio (SSMS) or Azure Data Studio.
  • Look specifically for patterns like INSERT INTO TableA SELECT * FROM (INSERT INTO TableB OUTPUT INSERTED.* INTO @TempVar ...).
  • Confirm whether the nested INSERT is wrapped inside a CTE, subquery, or INSERT...EXEC block.

Step 2: Refactor the Query to Separate the Operations

  • Break the single nested statement into two sequential, independent statements.
  • First, run the inner INSERT with its OUTPUT INTO clause targeting a table variable or temporary table (e.g., DECLARE @OutputTable TABLE (...)).
  • Second, run a separate INSERT INTO TableA SELECT * FROM @OutputTable to move the captured data into the final destination.

Step 3: Update Stored Procedures or ORM-Generated Scripts

  • If the nested INSERT originates from an Entity Framework, Dapper, or other ORM-generated query, check the mapping configuration for triggers or computed columns that may be forcing an automatic OUTPUT INTO injection.
  • Manually override the generated SQL in the stored procedure to use the two-step pattern from Step 2.
  • Save the updated procedure using ALTER PROCEDURE and redeploy via SQL Server Management Studio or your CI/CD pipeline.

Step 4: Test in a Non-Production Environment First

  • Deploy the refactored script to a staging instance of SQL Server 2025 running on Windows Server 2025 or Windows 11.
  • Execute the script manually in SSMS to confirm Error 10720 no longer appears.
  • Check SQL Server Error Logs (C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG) for any residual warnings.

Alternative or Verification Steps

  • Run SELECT * FROM @OutputTable immediately after the refactored insert to confirm rows were captured correctly before the second insert executes.
  • If refactoring is not immediately possible, use a trigger on the target table to log INSERTED values instead of relying on OUTPUT INTO within a nested structure.