Need help on building CAML Query

亡梦爱人 提交于 2019-12-13 03:42:11

问题


I have this table

    Col1  | Col2  | Col3
 1  MeYou | You   | Them
 2  Them  | They  | You
 3  Them  | Me    | They
 4  They  | Us    | We
 5  Us    | Them  | MeAsk

I would like to do these Query

Select all rows from MyTable 
Where Col1 contains 'Me' or Col2 contains 'Me' or Col3 contains 'Me'

Select all rows from MyTable 
Where (Col1 contains 'Me' or Col3 contains 'Me') and Col2 equals to 'Them'

Based on the table shown and using the condition that I wanted on my query, Query 1 should get 3 rows in return. The returned rows must be row1, row3 and row5. Query 2 should get only 1 row in return and that is row5.

My question is how am I going to compose this kind of query in CAML query for my sharepoint apps?

Thanks in advance :)


回答1:


First Query

<Where>
  <Or>
     <Contains>
        <FieldRef Name='Col1' />
        <Value Type='User'>22</Value>
     </Contains>
     <Or>
        <Contains>
           <FieldRef Name='Col2' />
           <Value Type='User'>22</Value>
        </Contains>
        <Contains>
           <FieldRef Name='Col3' />
           <Value Type='User'>22</Value>
        </Contains>
     </Or>
  </Or>
</Where>

second Query

<Where>
    <Or>
        <Contains>
            <FieldRef Name="Col1" /> 
            <Value Type="User">22</Value>
        </Contains>
        <And>
            <Contains>
                <FieldRef Name="Col2" /> 
                <Value Type="User">23</Value>
            </Contains>
            <Contains>
                <FieldRef Name="Col3" /> 
                <Value Type="User">22</Value>
            </Contains>
        </And>
    </Or>
</Where>


来源:https://stackoverflow.com/questions/5255143/need-help-on-building-caml-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!