DECLARE @Data AS XML = '
<Catalog>
<Artist>
<name>Wolfgang</name>
<name>Razorback</name>
</Artist>
<Album>
<Category>Rock</Category>
<Category>Alternative</Category>
</Album>
</Catalog>'
SELECT
B.value('(text())[1]','varchar(15)') as Artist,
C.value('(text())[1]','varchar(15)') as Album
FROM @Data.nodes('/Catalog') AS Catalog(A)
CROSS APPLY A.nodes('Artist/name') as Artist(B)
CROSS APPLY A.nodes('Album/Category') as Album(C)
我期待的结果应该是这样的,我真的只是想把艺术家作为第一列,专辑作为第二列
但它返回了这个查询,