SQL Server 2008 R2에서 XML을 구문 분석하려고하는데 몇 가지 문제가 있습니다. 각 부모 노드의 항목을 구문 분석하려고하지만 데이터가 정확하지 않은 것 같습니다. XML 데이터는 다음과 같습니다 :SQL Server 2008 R2에서 복합 XML 쿼리
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Project.xsd" Name="Job">
<Design>
<Catalog>
<Identification>
<Name>Group1</Name>
</Identification>
<FeatureSet ID="IDFS-1" Type="Style">
<Description>Style1</Description>
</FeatureSet>
<Item ID="IDI-1-2730">
<UserCode>Item1</UserCode>
<LineItemNumber>1</LineItemNumber>
</Item>
<Item ID="IDI-1-1595">
<UserCode>Item2</UserCode>
<LineItemNumber>2</LineItemNumber>
</Item>
</Catalog>
<Catalog>
<Identification>
<Name>Group2</Name>
</Identification>
<FeatureSet ID="IDFS-1" Type="Style">
<Description>Style2</Description>
</FeatureSet>
<Item ID="IDI-1-2730">
<UserCode>Item3</UserCode>
<LineItemNumber>1</LineItemNumber>
</Item>
</Catalog>
</Design>
</Project>
이것은 내가 지금까지 가지고있는 SQL이지만, 제대로 동작하지 않습니다.
select
x.d.query('./UserCode').value('.','char(40)') as UserCode
,x.d.query('./LineItemNumber').value('.','char(40)') as lineitemnumber
,i.d.query('./Name').value('.','nvarchar(200)') as [Group]
,u.d.query('./Description').value('.','nvarchar(200)') as Style
from
@xml.nodes('/Project/Design/Catalog/Item') as x(d)
outer apply
@xml.nodes('/Project/Design/Catalog/Identification') as i(d)
outer apply
@xml.nodes('/Project/Design/Catalog/FeatureSet') as u(d)
은 분명히 나는 XML 데이터 유형 위의 XML 데이터에
@xml
를 설정하고있다.
UserCode lineitemnumber Group Style
Item1 1 Group1 Style1
Item1 1 Group1 Style2
Item1 1 Group2 Style1
Item1 1 Group2 Style2
Item2 2 Group1 Style1
Item2 2 Group1 Style2
Item2 2 Group2 Style1
Item2 2 Group2 Style2
Item3 1 Group1 Style1
Item3 1 Group1 Style2
Item3 1 Group2 Style1
Item3 1 Group2 Style2
내가 무엇을 찾고 있어요 것은 : 아래
내가 무엇입니까 결과입니다UserCode lineitemnumber Group Style
Item1 1 Group1 Style1
Item2 2 Group1 Style1
Item3 1 Group2 Style2
모든 카탈로그는 하나의 성분/설명이있을 것이다 또한 하나 된 형상이있을 것이다
/설명
에서 훨씬 더 나은 예상 계획이 정확히 무엇을 즉 내가 찾고 있어요. 고마워요! –
@FredPhillips, 오신 것을 환영합니다. 하지만 부모 노드 ('../ Identification/Name ')')와 같은 부모 노드로 돌아가는 것은 과도한 연산이므로 대용량 데이터에서 성능 문제를 일으키는 것을 알아야합니다 – Backs