If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Insert, Delete a Node from XML Data Column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-14-11, 11:05
somu somu is offline
Registered User
 
Join Date: Jul 2011
Posts: 4
Insert, Delete a Node from XML Data Column

Hi,
I wanted to insert the following node in the sql table column. I got following error

Msg 2226, Level 16, State 1, Line 10
XQuery [#tmpAbc.x.modify()]: The target of 'insert' must be a single node, found 'element(Items,xdt:untyped) *'


Create Table #tmpAbc ( x xml)
go
insert into #tmpAbc values('
<ScreenState xmlns="shared" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Items>
<ScreenStateItem>
<Key>Tab</Key>
<Value>0</Value>
</ScreenStateItem>
<ScreenStateItem>
<Key>AllPortfolio</Key>
<Value>True</Value>
</ScreenStateItem>
</Items>
</ScreenState>')
go
select * from #tmpAbc
go

declare @allNode xml
set @allNode='<ScreenStateItem>
<Key>AllPortfolio</Key>
<Value>True</Value>
</ScreenStateItem>'

update #tmpAbc
set x.modify( 'insert sql:variable("@allNode")
before (/ScreenState/Items[1])
')



go
select * from #tmpAbc
go

drop table #tmpAbc
Reply With Quote
Reply

Tags
delete, insert, sql, xml, xpath

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On