0

I have a table1

Deptno  Skills

1       1
1       2
1       3
2       1
2       3
3       1
3       2

I need to insert the skills value as a child node to an XMl column in table2 with respect to matching Deptno

Tried using

UPDATE 
   Dept
SET 
   XMLColumn.modify('insert ('Skills 2 /Skills)
   as last into
   (/Skills[1])
   ') where deptno = 1

But how can I use other table values and nest them into table2 xml column?

1 Answer 1

1
update T2
set XMLColumn.modify('insert sql:column("T1.Skills") as last into Skills[1]')
from Table2 as T2
  cross apply (
              select T1.Skills
              from Table1 as T1
              where T2.Deptno = T1.Deptno
              for xml path(''), type
              ) as T1(Skills)
where T2.Deptno = 1

Build the XML you want to insert in a cross apply correlated on Deptno and use sql:column() to pull the generated XML into your modify() statement.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.