how to split a xml format data into row column format in sql server 2008 using stored procedure -
i getting response asp.net web service mentioned in below format . want convert in table format age in age column , date in date column. have asked question earlier string getting o/p in xml should do?
getting response output in @response in format :
<?xml version="1.0" encoding="utf-8"?> <string xmlns="http://abc.org/">age=7|date=15/04/2006^age=5|date=15/04/2008</string>
how split row column format in sql server 2008 using stored procedure.i getting @response above mentioned form unable use way doing . can me.
use string split function of choice , split on ^
first , |
second. after can use pivot
data in columns.
declare @xml xml = '<?xml version="1.0" encoding="utf-8"?><string xmlns="http://abc.org/">age=7|date=15/04/2006^age=5|date=15/04/2008</string>'; xmlnamespaces(default 'http://abc.org/') select p.age, p.date ( select s1.id, left(s2.item, charindex('=', s2.item) - 1) colname, stuff(s2.item, 1, charindex('=', s2.item), '') value splitstring(@xml.value('string[1]', 'varchar(max)'), '^') s1 cross apply splitstring(s1.item, '|') s2 ) x pivot ( min(x.value) x.colname in (age, date) ) p;
Comments
Post a Comment