Need help on building CAML Query
Asked Answered
M

1

0

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 :)

Mullen answered 10/3, 2011 at 3:32 Comment(2)
Make sure you download and use this: u2u.net/res/Tools/CamlQueryBuilder.aspx if you haven't already.Ticket
Yup I already have the CamlQueryBuilder, my only problem is I don't know how to build a query.Mullen
D
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>
Dhu answered 10/3, 2011 at 12:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.