Why This Error Happens
This error occurs when SQL Server 2025 encounters a nested INSERT...EXEC statement where the inner stored procedure or dynamic SQL attempts to return more than one column in its result set. The Query Optimizer strictly enforces a single-column restriction on nested inserts because the outer INSERT statement cannot resolve a multi-column mapping when a secondary execution context is already active. This typically surfaces after upgrading to SQL Server 2025 on Windows Server 2025, where stricter parsing of nested procedure calls now flags syntax that may have silently worked—or thrown a different warning—in older engine versions.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Nested INSERT Statement
- Open SQL Server Management Studio (SSMS) and locate the exact stored procedure or batch referenced in the error output.
- Check the
sys.dm_exec_sql_textDMV or SQL Server Profiler/Extended Events trace to capture the exact query text that triggered Error 4155. - Confirm whether the procedure contains an
INSERT INTO TableName EXEC AnotherProcedurepattern whereAnotherProcedureitself contains a nestedINSERT...EXEC.
Step 2: Refactor the Nested Logic to Avoid Double EXEC Nesting
- Rewrite the inner procedure to populate a temporary table (
#TempTable) or table variable instead of directly nesting anotherEXECinside anINSERT. - Example fix:
INSERT INTO #TempResults
EXEC dbo.InnerProcedure;
INSERT INTO FinalTable (Col1)
SELECT Col1 FROM #TempResults;
- Ensure the inner
SELECTstatement being inserted ultimately resolves to exactly one column perINSERTtarget when nesting cannot be avoided.
Step 3: Validate Compatibility Level and Query Hints
- Run
SELECT compatibility_level FROM sys.databases WHERE name = 'YourDBName';to confirm the database compatibility level matches SQL Server 2025 standards (170). - If the procedure was migrated from an older SQL Server version, test with
ALTER DATABASE YourDBName SET COMPATIBILITY_LEVEL = 160;temporarily to see if legacy parsing resolves the issue (useful for diagnosis, not a permanent fix). - Remove any unnecessary
OUTPUTclauses or multi-columnSELECTstatements inside the nestedEXECcall.
Step 4: Apply Latest Cumulative Update
- On Windows Server 2025, open Windows Update or use
SSMS > Help > Check for Updatesto confirm you are on the latest Cumulative Update (CU) for SQL Server 2025, as early CUs had known parser regressions affecting nestedINSERT...EXECvalidation. - Restart the SQL Server service via
services.mscorRestart-Service MSSQLSERVERin PowerShell (run as Administrator) after patching.
Alternative or Verification Steps
- Re-run the original stored procedure or batch in SSMS and confirm Error 4155 no longer appears in the Messages tab; check the Windows Event Viewer (Application Log) to ensure no related SQL Server exceptions were logged.
- If the error persists, bypass nested execution entirely by converting the inner procedure logic into a Table-Valued Function (TVF) and referencing it directly in the outer
INSERT INTO ... SELECTstatement.