i have generated a temp table from xml and it has the following structure
column1 column2
id 1234
code ukjk
.
.
there will be another 60 rows again
id 4586
code ouiu
.
.
there will be another 60 rows again
id 78545
code khdsjf
like this there will be 15 id's in the table
Now i want to convert the rows into column like
i don't want all the 60 i need just 5 of them
id code vdb_id guid ....
1234
4586
78545
and also i have attached the XML file image..
i have used pivot function
IF OBJECT_ID('tempdb..#xml_final') IS NOT NULL DROP TABLE #xml_final
CREATE TABLE #xml_final (rownum int, Project_id int, Project_Name varchar(60), Project_manager_id int, Updated_date varchar(60) )
insert into #xml_final
SELECT * FROM
(
SELECT xmlData.Result.value('v[1]','VARCHAR(200)') AS A,
xmlData.Result.value('n[1]','VARCHAR(200)') AS B,
ROW_NUMBER() over(PARTITION BY xmlData.Result.value('n[1]','VARCHAR(200)')
order by xmlData.Result.value('v[1]','VARCHAR(200)')) AS Num
FROM @xmlData.nodes('//result/rows/row/f') xmlData(Result)
) AS A
Pivot (Min(A) FOR B IN ([id] ,
[summary],
[manager_id],
[ts]
)
) piv
But it is not working properly.. i am getting mismatch error
for example
id 1234 i am getting code as ouiu
How to solve this issue..
how can i read multiple xml values from URL through t-sql
No comments:
Post a Comment