我是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