I have the below XML:
create table #temp(cid int,xml_data xml)
insert into cid
values(1001,
'<Main>
<name>''John doe''</name>
<age>15</age>
</Main>')
I want to add an additional node to this XML based on a simple parametric condition:
desired output:
<Main>
<name>John doe</name>
<type>Q</type>
<age>15</age>
</Main>
code:
select case when @type = 'Q' then
UPDATE #temp
SET Main.modify('insert <type = 'Q'> into
(/Main)')
GO
I am getting syntax error. Any help!
UPDATE:
I implemented the suggested solution in my code and I'm getting below error. Missing out something silly!
UPDATE #temp
SET xml_data =
case
when @type = 'G'
then xml_data.modify('insert <type>G</type> into (/Main)[1]');
when @type = 'Q'
then xml_data.modify('insert <type>Q</type> into (/Main)[1]'); end
I am getting 'Incorrect use of the XML data type method 'modify'. A non-mutator method is expected in this context.' error

insert <type = 'Q'>trys to insert a not well-formed node... Btw: Do you really want to wrap "John doe" in quotes?