XML exists() for deletion in tsql

danieli

New Member
When I try to delete an XML element that is not in the XML schema, I get \[quote\] Msg 2260, Level 16, State 1, Line 13
XQuery [Table_name.Table_XML_field.exist()]: There is no element named 'XML_element_name'\[/quote\]despite wrapping the delete in a boolean\[code\]IF EXISTS (select 'x'from sys.xml_schema_collections xsc inner join sys.xml_schema_elements xse on xsc.xml_collection_id = xse.xml_collection_idwhere 1 = 1and xse.is_qualified = 0and xsc.name = 'XML_schema_name'and xse.name = 'XML_element_name')BEGINUPDATE Table_nameSET Table_XML_field.modify(' delete (//XML_element_name)')WHERE Table_XML_field.exist('(//XML_element_name)[1]') = 1END\[/code\]I wrap the deletion in a boolean condition, and still get that error. Is there a different way to not execute the "UPDATE" statement if the XML node does not exist?
 
Back
Top