CAML query with nested AND's and OR's for multiple fields in SharePoint

I have some cases about CAML in SharePoint. there are how to make condition like this :

AND (FirstName = 'A' OR LastName = 'A' OR Description = 'A' OR Profile='A')
  AND (FirstName = 'B' OR LastName = 'B' OR Description = 'B' OR Profile='B')
in SharePoint we use CAML if we want to see "AND OR" condition in sharepoint list view. 
open your page of view what your want to edit. for example AllItem.aspx under form in document library.
but before that you should set first condition "AND OR" in view you want to edit using sharepoint designer.

Since you are not allowed to put more than two conditions in one condition group (And | Or) you have to create an extra nested group (MSDN). The expression A AND B AND C looks like this:

<And>
    A
    <And>
        B
        C
    </And>
</And>

it is sample translated to CAML (hopefully with matching XML tags :

        <And>       
            <Or>
                <Eq>
                    <FieldRef Name='FirstName' />
                    <Value Type='Text'>A</Value>
                </Eq>
                <Or>
                    <Eq>
                        <FieldRef Name='LastName' />
                        <Value Type='Text'>A</Value>
                    </Eq>
                    <Eq>
                        <FieldRef Name='Profile' />
                        <Value Type='Text'>A</Value>
                    </Eq>
                </Or>
            </Or>
            <Or>
                <Eq>
                    <FieldRef Name='FirstName' />
                    <Value Type='Text'>B</Value>
                </Eq>
                <Or>
                    <Eq>
                        <FieldRef Name='LastName' />
                        <Value Type='Text'>B</Value>
                    </Eq>
                    <Eq>
                        <FieldRef Name='Profile' />
                        <Value Type='Text'>B</Value>
                    </Eq>
                </Or>
            </Or>
        </And>

Komentar

Postingan populer dari blog ini

You cannot view a list in Datasheet view on a SharePoint

Synchronizing an Excel file with SharePoint