declare @xmlsample xml =
'<root>
<solution>
<solutionnumber>1</solutionnumber>
<productgroup>
<productcategory>
<price>100</price>
<title>Some product</title>
<tax>1</tax>
</productcategory>
</productgroup>
<productcategory2>
<price>200</price>
<title>Some other product</title>
<tax>2</tax>
</productcategory2>
</solution>
<solution>
<solutionnumber>2</solutionnumber>
<productcategory2>
<price>200</price>
<title>Some other product</title>
<tax>2</tax>
</productcategory2>
</solution>
</root>'
SELECT
--T.C.value('(./ancestor::ns1:solutionNumber)[1]', 'varchar(50)') AS solutionnumber ?? no clue
T.C.value('(price)[1]', 'numeric(18,2)') AS price
,T.C.value('(title)[1]', 'varchar(50)') AS title
,T.C.value('(tax)[1]', 'numeric(18,2)') AS tax
FROM @xmlsample.nodes('//node()[title]') AS T(C)
Biểu diễn XML tôi đang cố gắng băm nhỏ trong SQL Server 2008 r2. Tôi tìm thấy nút "tiêu đề" và lấy các giá trị tôi cần có trong danh mục sản phẩm. Bây giờ tôi muốn nhận được "số giải pháp" tuy nhiên điều này có thể là một hoặc nhiều nút cha trên sản phẩm vì có một số nhóm "sản phẩm nhất định".SQL Server .nodes() Nút cha mẹ XML theo tên
Tôi làm cách nào để kiểm tra các nút cha theo tên ("solutionnumber") cho đến khi tôi tìm thấy? Cảm ơn bạn đã hỗ trợ.
thuật ngữ không chính xác về một phần của tôi. Tuy nhiên, tìm kiếm "solutionnumber". – duffn