I have a column in my SQL Server table with this XML value :
<ValidTestResult version="1.0" encoding="UTF-8">
<item CarType="پراید" SystemType="2" model="1382">
<count>7777</count>
</item>
<item CarType="1" SystemType="2" model="1382">
<count>100</count>
</item>
<item CarType="1" SystemType="2" model="1380">
<count>100</count>
</item>
</ValidTestResult>
I want to check if a node exists, update the value of count. I do that using this code:
UPDATE InquiryStatus
SET TotalCarburetorResult.modify(N'replace value of
(/ValidTestResult/item[@model=("1382") and @CarType=("پراید")]/count/text())[1] with ("7777")') where id=27
GO
UPDATE InquiryStatus
SET TotalCarburetorResult.modify(N'insert <item CarType="پراید" SystemType="2" model="1382"><count>100</count></item> into (/Result)[1]')
As you can see my code inserts and updates the value, but I need something else: I want to check if the node exists, then update the value count and if doesn't exist, it should insert a new node. How can I check if the node exists?
For example a node with this attributes:
<item CarType="1" SystemType="2" model="1382">