I have data serialized to a XML column in a SQL Server table in the form:
<Form title="Sample Data">
<MyProperty>1234</MyProperty>
<Employee>
<MyProperty>1234</MyProperty>
</Employee>
</Form>
The element MyProperty can either be at the root level, or a child element under <Employee>.
What I need is a SQL script that:
- Checks to see if
MyPropertyexists at the root level of the XML (I don't care about the child version of it) - If it doesn't exist, insert the record at the root level.
The value of MyProperty will have been previously calculated and I plan to place it into a temp table, along with the PK of the row that has the serialized XML.
Can anyone give some guidance on how to do this?
exist()method and try to implement it for your case