我是XQuery的新手,并且遇到一些问题。这是我的例子。使用XQuery获取此数据
我有这个变量:
declare @xmlDoc XML
它存储在它的下面的XML:
<?xml version="1.0" encoding="utf-8"?>
<NewDataSet>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:Locale="">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table1">
<xs:complexType>
<xs:sequence>
<xs:element name="Sharedparam" type="xs:string" minOccurs="0" />
<xs:element name="Antoher" type="xs:string" minOccurs="0" />
<xs:element name="RandomParam2" type="xs:string" minOccurs="0" />
<xs:element name="MoreParam" type="xs:string" minOccurs="0" />
<xs:element name="ResultsParam" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<Table1>
<Sharedparam>shared</Sharedparam>
<Antoher>sahre</Antoher>
<RandomParam2>Good stuff</RandomParam2>
<MoreParam>and more</MoreParam>
<ResultsParam>2</ResultsParam>
</Table1>
<Table1>
<Sharedparam>Hey</Sharedparam>
<Antoher>what </Antoher>
<RandomParam2>do you</RandomParam2>
<MoreParam>think</MoreParam>
<ResultsParam>2</ResultsParam>
</Table1>
<Table1 />
</NewDataSet>
如何选择Sharedparam的所有值? (还是真的返回值(不是XML任何像样的查询)将是巨大的。)
什么我真的希望做的是得到一个结果集是这样的:
Name Value1 Value2 Value3 Value4
Sharedparam shared Hey Null Null
Another share what Null Null
....
这会对我忽略任何超出“Value4”的数据(这对我使用这些数据是可以接受的)。
这是一个奇怪的布局。您期望列Sharedparam,Antoher等:不行。如果我读得对,Table1'maxOccurs =“unbounded”'这意味着可变数量的列=不是SQL – gbn 2011-05-24 19:09:37
我会忽略Value4以外的任何内容 – Vaccano 2011-05-24 19:15:35