replace value of (XML DML)
XML DML replace value of (inside modify())
What changes
- Input
- target node and new value
- Output or change
- the xml instance being modified
Syntax at a glance
replace value of Expression1 with Expression2
Work example
Replace the value of one existing text node or attribute.
Select a single value node with a positional predicate and check how the value is serialized.
Check your work replace value of changes a node value and does not replace the node's element structure.
Practice SQL
Open in SQL FlowDECLARE @doc xml = N'<Order><Item quantity="2" /></Order>'; SET @doc.modify('replace value of (/Order/Item/@quantity)[1] with "3"'); SELECT @doc AS updated_xml;
Open Microsoft Learn for full syntax, permissions, and details for your version.