3
压扁XML我有这样的XML在T-SQL:在SQLXML
<Elements>
<Element>
<Index>1</Index>
<Type>A</Type>
<Code>AB</Code>
<Time>1900-01-01T10:21:00</Time>
</Element>
<Element>
<Index>2</Index>
<Type>M</Type>
<Code>AL</Code>
<Time>1900-01-01T10:22:00</Time>
</Element>
</Elements>
我想找回它作为一个表:
Index FieldName FieldValue
-------- ------------ ----------
1 Index 1
1 Type A
1 Code AB
1 Time 1900-01-01T10:21:00
2 Index 2
2 Type M
2 Code AL
2 Time 1900-01-01T10:22:00
当然,我正在寻找在这里是将元素节点转换为行,但我无法获得更多的字段值或索引在一次...
select
-- r.value('.[1]', 'nvarchar(10)') Value,
-- r.value('fn:local-name(.)', 'nvarchar(50)') FieldName
r.value('Index[1]', 'nvarchar(10)') f,
r.value('./node()[fn:local-name(.)]', 'nvarchar(10)') v
from
@content.nodes('/Elements/*') as records(r)
完美!谢谢! :) – 2010-07-06 10:31:17
我刚刚加了一点:WHERE SubEl.SubElem.value('local-name(。)','varchar(100)')<>'Index' – 2010-07-06 10:35:41