1
我有以下模式運行SQL XML時,返回四個項目:SQL Server 2008 R2的SQLXML和XPath查詢過濾器不工作
<xsd:element name="iati-activities" sql:relation="IATI.ACTIVITIES" sql:key-fields="BUSINESS_UNIT">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="iati-activity" sql:relation="IATI.PROJECT_METADATA" sql:relationship="ACTIVITIES_ACTIVITY">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ProjectId" type="xsd:string" sql:field="PROJECT_ID" sql:key-fields="PROJECT_ID" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:complexType>
</xsd:element>
我想:
<iati-activities>
<iati-activity>
<ProjectId>00072877</ProjectId>
</iati-activity>
</iati-activities>
但在運行它時不過濾。這裏是XPath查詢使用:
<root xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:header sql:nullvalue="ISNULL">
<sql:param name="ProjectId">00072877</sql:param>
</sql:header>
<sql:xpath-query mapping-schema="activity_schema.xsd">
iati-activities[iati-activity/ProjectId=$ProjectId]
</sql:xpath-query>
</root>
這是我得到什麼:
<iati-activities>
<iati-activity>
<ProjectId>00072877</ProjectId>
</iati-activity>
<iati-activity>
<ProjectId>00059626</ProjectId>
</iati-activity>
<iati-activity>
<ProjectId>...</ProjectId>
</iati-activity>
<iati-activity>
<ProjectId>...</ProjectId>
</iati-activity>
</iati-activities>
如果我使用下面的查詢:
<root xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<sql:header sql:nullvalue="ISNULL">
<sql:param name="ProjectId">00072877</sql:param>
</sql:header>
<sql:xpath-query mapping-schema="activity_schema.xsd">
iati-activities/iati-activity[ProjectId=$ProjectId]
</sql:xpath-query>
</root>
我得到了下面沒有IATI -acitivties元素:
<iati-activity>
<ProjectId>00072877</ProjectId>
</iati-activity>
A呃,一個人知道我在做什麼錯了?