Troubleshooting Guide: SQL Server Error 2373 – “%s%ls is not supported with constructed XML”
Why This Error Happens
This error occurs when an operation—such as creating an index, applying a constraint, or executing certain DML operations—is attempted on XML data that was generated dynamically (constructed) rather than retrieved directly from a typed XML column or variable. SQL Server 2025 restricts operations like indexing or schema validation on constructed XML because it lacks the persistent structure and schema binding required for these features. This typically surfaces in queries that use FOR XML, XML methods (like .query() or .nodes()), or functions that return XML results on-the-fly within a nested query, rather than reading from a stored, schema-validated XML column.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Query or Operation
- Review the exact T-SQL statement that triggered Error 2373 using SQL Server Management Studio (SSMS) or the Extended Events log.
- Check Windows Event Viewer under Applications and Services Logs > Microsoft > SQL Server for the full error context and the
%lssubstitution value, which indicates the specific unsupported operation (e.g., indexing, schema collection binding). - Confirm whether the XML data originates from a function, subquery, or
FOR XMLclause rather than a native XML column.
Step 2: Materialize the XML Before Performing the Operation
- Instead of operating directly on constructed XML, insert the result into a temporary table or table variable with a proper
XMLtyped column first. - Example fix:
DECLARE @TempXML TABLE (XmlData XML);
INSERT INTO @TempXML
SELECT (SELECT * FROM YourTable FOR XML AUTO);
- Now apply indexing, constraints, or further XML methods against
@TempXML.XmlDatainstead of the inline constructed result.
Step 3: Rebind or Recreate XML Schema Collections (If Applicable)
- If the error relates to schema-bound XML operations, verify the XML Schema Collection is correctly attached to a persisted column:
ALTER TABLE YourTable
ALTER COLUMN XmlColumn XML (YourSchemaCollectionName);
- Ensure the schema collection exists and is not orphaned by running:
SELECT * FROM sys.xml_schema_collections WHERE name = 'YourSchemaCollectionName';
Step 4: Apply Latest SQL Server 2025 Cumulative Update
- Navigate to Microsoft Update Catalog and confirm the instance is running the latest Cumulative Update (CU) for SQL Server 2025, as early builds had stricter XML construction validation that has since been patched.
- Verify current build version by running:
SELECT @@VERSION;
- Install any pending updates via Windows Update or the standalone SQL Server Setup package, then restart the SQL Server (MSSQLSERVER) service from
services.msc.
Alternative or Verification Steps
- Re-run the original query against the materialized temporary table/variable version to confirm Error 2373 no longer appears in SSMS or the Windows Application Event Log.
- If the issue persists, as a workaround, cast the constructed XML result explicitly using
CAST(... AS XML)into a declared variable before passing it to any indexing or schema-validation operation.