开发者

how to transform this xml field into a table?

I got this in a XML field in sql server 2005

<Details>
  <Attribute Type="org">6800</Attribute>
  <Attribute Type="fac">100</Attribute>
  <Attribute Type="fac">200</Attribute>
</Details>

what would be 开发者_如何学编程the syntax to transform this into a table, like this

 col_Type col_value
    org      6800
    fac      100
    fac      200

I'm currently stuck with singleton error while writing my query


found how to do it

if someone want to know how:

    declare @XmlContent xml

    set @XmlContent = '<Details>
      <Attribute Type="org">6800</Attribute>
      <Attribute Type="fac">100</Attribute>
      <Attribute Type="fac">200</Attribute>
    </Details>'

    SELECT
             Details.Attribute.value('(@Type)[1]', 'varchar(10)') AS 'Type',
             Details.Attribute.value('(.)[1]', 'int') AS 'Value'
          FROM
             @XmlContent.nodes('/Details/Attribute') AS Details(Attribute)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜