0

I have a table1 as

id  value1  Xmlvalue
 1   abc    <value value1=abc id = 1>           
 2   abcd   <value value1=abcd id = 2>        
 3   defg   <value value1=defg id = 3>          
 4   def    <value value1=def id = 4>
 5   ghi    <value value1=ghi id = 5> 

and table2 as

id   value1  Xmlvalue   
1,2  abc            
3,4  def            
5    ghi  

I need output table as

id   value1  Xmlvalue   
1,2  abc     <root><value value1=abc id = 1><value value1=abcd id = 2></root>       
3,4  def     <root><value value1=defg id = 3><value value1=def id = 4></root>       
5    ghi     <root><value value1=ghi id = 5></root>     

Note: My XmlValue columns are of type varchar(max). I have used these columns in other queries in same store procedure and if I make these columns of type XML then it gives me error in group by.

sandeep.gosavi
  • 610
  • 2
  • 10
  • 27
  • This has been asked and answered thousands of times. – Sean Lange Sep 21 '17 at 14:05
  • Please focus on ID column. How to match id? – sandeep.gosavi Sep 22 '17 at 04:14
  • Ugh. Didn't notice you also have delimited data in Table2. You need a string splitter for that. Here is my choice for a string splitter. http://www.sqlservercentral.com/articles/Tally+Table/72993/ If you don't like that one here are some other excellent choices. http://www.sqlservercentral.com/articles/Tally+Table/72993/ Keep in mind that you should not be storing data like that. It violates 1NF and causes lots of pain. – Sean Lange Sep 22 '17 at 13:14

0 Answers0