3

SQL Server と T-SQL は初めてです。SQL Server 2008 R2 でこの xml に格納されている情報を照会するにはどうすればよいですか?

XML :

<smp:Root xmlns:smp="http://tempuri.org/smp.xsd" header="Test Title">
  <smp:Sections>
    <smp:G3 idnumber="01">
      <SectionHost>ABC</SectionHost>
    </smp:G3>
    <smp:G2 idnumber="01">
      <SectionHost>DEF</SectionHost>
    </smp:G2>
  </smp:Sections>
</smp:Root>
4

1 に答える 1

3

を列にXml格納している場合は、をに使用するだけです。Xmlvalue methodshredXml

次回はDDL, DML、試したこと、テーブル構造などを示すためにいくつか投稿してみてください。

しかし、これを試してください

WITH XMLNAMESPACES (Default 'http://tempuri.org/smp.xsd')
SELECT     
    a.value('@header', 'nvarchar(50)') as Header,
    b.value('local-name(.)', 'nvarchar(50)') as Sections,
    b.value('@idnumber' ,'int') as IdNumber,
    b.value('.' , 'nvarchar(20)') as Host

From ATable As x   

                Cross Apply x.AXmlColumn.nodes('Root') a(a) 
                               Cross Apply a.nodes('Sections/*') b(b)

links始めるのに役立つものを次に示します。

https://www.simple-talk.com/sql/learn-sql-server/the-xml-methods-in-sql-server/

http://blog.sqlauthority.com/2008/01/15/sql-server-what-is-dml-ddl-dcl-and-tcl-introduction-and-examples/

http://msdn.microsoft.com/en-us/library/ms189254.aspx

于 2013-06-22T22:32:00.713 に答える