What would XQuery look like to check if a node exists, and if it does, run the replace statement, if not, then the insert statement?
Here is what I mean. I want to save if the user has read the important message in XML. Here's what the data looks like.
<usersettings>
<message haveRead="0" messageId="23" ></message>
<message haveRead="1" messageId="22" ></message>
</usersettings>
Basically this XML tells me that the user has read one message while the other message still needs to be viewed / read.
I want to combine my xquery insert / replace into a single statement. That's what I meant.
UPDATE WebUsers SET UserSettings.modify('
declare default element namespace "http://www.test.com/test";
IF a node exists with the messageId
code to replace node with new update
ELSE
code to insert a new node with the provided variables
')
WHERE Id = @WebUserId
source
share