Add perent element

I want to add perent element to existing element in xml variable (SQL 2005). I solve that problem with:
DECLARE @a xml
SET @a = N'<EVENT_INSTANCE><a>CREATE_TYPE</a><b1>2005-10-14T01:58:28.070</b1><c>51</c></EVENT_INSTANCE>'

SELECT @a
SET @a.modify(' insert (<AddElement></AddElement>)
after (/EVENT_INSTANCE/a)[1]')

select @a
SET @a.modify(' insert /EVENT_INSTANCE/b1
as first into (/EVENT_INSTANCE/AddElement)[1]')
select @a
SET @a.modify(' delete /EVENT_INSTANCE/b1')
SELECT @a

Is there any simplier solution.
Thanks

[717 byte] By [AnaMihalj] at [2008-2-7]
# 1
You can use XQuery FLWR expression to construct your XML.

DECLARE @a xml
SET @a = N'<EVENT_INSTANCE><a>CREATE_TYPE</a><b1>2005-10-14T01:58:28.070</b1><c>51</c></EVENT_INSTANCE>'
SELECT @a.query('
for $a in /EVENT_INSTANCE
return
<EVENT_INSTANCE>
{
for $a1 in $a/*
return if (local-name($a1)="b1") then <AddElement>{$a1}</AddElement>
else $a1
}
</EVENT_INSTANCE>')

JinghaoLiu at 2007-9-8 > top of Msdn Tech,SQL Server,SQL Server XML...

SQL Server

Site Classified