상세 컨텐츠

본문 제목

SQL-Server sp 에서 xml 처리

DataBase/SQL Server

by 탑~! 2011. 3. 24. 11:55

본문


declare @xmlData    xml

set @xmlData = '<NewDataSet>
    <FixOrCancelList>
   <Vessel>06100</Vessel>
   <Voy>0001</Voy>
   <FixYN>Y</FixYN>
    </FixOrCancelList>
    <FixOrCancelList>
   <Vessel>06100</Vessel>
   <Voy>0002</Voy>
   <FixYN>Y</FixYN>
    </FixOrCancelList>
    <FixOrCancelList>
   <Vessel>06100</Vessel>
   <Voy>0003</Voy>
   <FixYN>Y</FixYN>
    </FixOrCancelList>
    <FixOrCancelList>
   <Vessel>06166</Vessel>
   <Voy>0001</Voy>
   <FixYN>Y</FixYN>
    </FixOrCancelList>
    <FixOrCancelList>
   <Vessel>06166</Vessel>
   <Voy>0002</Voy>
   <FixYN>Y</FixYN>
    </FixOrCancelList>
    <FixOrCancelList>
   <Vessel>06166</Vessel>
   <Voy>0003</Voy>
   <FixYN>Y</FixYN>
    </FixOrCancelList>
    <FixOrCancelList>
   <Vessel>06166</Vessel>
   <Voy>0004</Voy>
   <FixYN>Y</FixYN>
    </FixOrCancelList>
  </NewDataSet>'
  
SELECT ItemData.Row.value('Vessel[1]', 'varchar(5)') Vessel
  ,ItemData.Row.value('Voy[1]', 'varchar(4)') Voy
  ,ItemData.Row.value('FixYN[1]', 'varchar(4)') FixYN
FROM @xmlData.nodes('/NewDataSet/FixOrCancelList') ItemData(row)

관련글 더보기