web-dev-qa-db-ja.com

XMLをデータベーステーブルに変換する方法

入力:

Declare @OUT xml
select @OUT = N'
<row>
  <kind>MainCat</kind>
  <sortid>1</sortid>
  <kind_id>1</kind_id>
  <PPoet>حافظ</PPoet>
  <MTitle>حافظ</MTitle>
  <Row>1</Row>
</row>'
select T.X.value('@Kind', 'nvarchar(50)') as kind,
T.X.value('@sortid', 'int') as sortid
from @out.nodes('/row') as T(X)

this select return NULL!
4
coditori

とても近い:

select 
  T.X.value('./kind[1]', 'nvarchar(50)') as kind,
  T.X.value('./sortid[1]', 'int') as sortid
from @out.nodes('/row') as T(X);
4
Aaron Bertrand