SharePoint中的AND OR AND CAML查询

时间:2013-06-07 18:15:53

标签: sharepoint caml

无法找到一个很好的方法来做到这一点。我在SharePoint中有一个视图,我想使用像(A和B)或(A和C)这样的查询进行过滤。我正试图在Sharepoint Designer的CAML中写这个,但我无处可去。这是我第一次使用CAML,所以没有帮助。这是我到目前为止所提出的:

<Where>
           <And>
                <Or>
                     <And>
                          <Eq>
                               <FieldRef Name="Component" />
                               <Value Type="Text">ComponentX</Value>
                          </Eq>
                          <Eq>
                               <FieldRef Name="Review_x0020_Canceled" />
                               <Value Type="Boolean">0</Value>
                          </Eq>
                     </And>
                </Or>
                <Eq>
                     <FieldRef Name="Component" />
                     <Value Type="Text">ComponentX</Value>
                </Eq>
                <IsNull>
                     <FieldRef Name="Actual_x0020_Finish_x0020_Date" />
                </IsNull>
           </And>
      </Where>

我希望这显示所有记录(Component = ComponentX AND Review Canceled = No)或(Component = ComponentX AND Actual Finish Date = Null)

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

试试这个:

<Where>
  <Or>
    <And>
      <Eq>
        <FieldRef Name='Component' />
        <Value Type='Text'>ComponentX</Value>
      </Eq>
      <Eq>
        <FieldRef Name='Review_x0020_Canceled' />
        <Value Type='Boolean'>0</Value>
      </Eq>
    </And>
    <And>
      <Eq>
        <FieldRef Name='Component' />
        <Value Type='Text'>ComponentX</Value>
      </Eq>
      <IsNull>
        <FieldRef Name="Actual_x0020_Finish_x0020_Date" />
      </IsNull>
    </And>
  </Or>
</Where>

will return the record with the blue background color

新代码caml:

<Where>
  <And>
    <And>
      <Eq>
        <FieldRef Name='Review_x0020_Canceled' />
        <Value Type='Boolean'>0</Value>
      </Eq>
      <Eq>
        <FieldRef Name='Component' />
        <Value Type='Text'>ComponentX</Value>
      </Eq>
    </And>
    <IsNull>
      <FieldRef Name='Actual_x0020_Finish_x0020_Date' />
    </IsNull>
  </And>
</Where>

答案 1 :(得分:0)

你的逻辑

(Component = ComponentX AND Review Canceled = NO) OR 
    (Component = ComponentX AND Actual Finish Date = NULL)

相当于

Component = ComponentX And (Review Canceled = NO OR Actual Finish Date = NULL)

这将是这个CAML查询:

<Where>
  <And>
    <Eq>
      <FieldRef Name="Component" />
      <Value Type="Text">ComponentX</Value>
    </Eq>
    <Or>
      <Eq>
        <FieldRef Name="Review_x0020_Canceled" />
        <Value Type="Boolean">0</Value>
      </Eq>
      <IsNull>
        <FieldRef Name="Actual_x0020_Finish_x0020_Date" />
      </IsNull>
    </Or>
  </And>  
</Where>