Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xml modify, any way to check attribute exists before inserting?

Status
Not open for further replies.

Maim

Programmer
Jun 25, 1999
106
CA
I have a record with an xml data type field. The value starts out raw, basically just a "<mynode />". I also have some procedures that handle related records (in the thousands) and it checks whether to perform taskA or taskB and add an attribute to the xml.

Does the xml dml have some way of checking if an attribute exists that I could use with the update table command?

example:
[tt]

update myXmlTable
set theXmlField.modify('insert attribute taskA {"abc"} into (/mynode)[1]')
where theId = 1

[/tt]

the above will work fine the first time but will obviously give an error when run a 2nd time. I also want to avoid checking if the attribute exists with the exist() method as this will absolutely kill the performance.

I'm hoping there would be a way to check along the lines of:

if attributeexists(taskA) then update it with "abc" else insert it with value of "abc"

Thanks in advance


-----------------------------------
&quot;Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.&quot; - Rich Cook
 
Why not wrap it within a TRY CATCH block. If you hit the CATCH it already exists and you should try an update.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top