More than two conditions in CAML query

CAML doesn’t support more than two conditions in a query. I just realized that I never needed more than two conditions in a query, but I just did when I was designing an SSRS report against a SharePoint list.
But there’s nothing to worry about, here is the workaround;

<Query>

<Where>

<Or>

    <Contains>

    <FieldRef Name=”Comment” />

    <Value Type=”Text”>    <Parameter Name=”SearchParam” />     </Value>

    </Contains>

<Or>

    <Eq>

    <FieldRef Name=”ID” />

    <Value Type=”Integer”><Parameter Name=”SearchParam” /></Value>

    </Eq>

<Or>

<Contains>

    <FieldRef Name=”Title” />

    <Value Type=”Text”><Parameter Name=”SearchParam” /></Value>

 </Contains>

<Contains>

    <FieldRef Name=”Record_x0020_Number” />

    <Value Type=”Text”>    <Parameter Name=”SearchParam” /></Value>

</Contains>

</Or>

</Or>

</Or>

</Where>

</Query>

Keep nesting for more conditions.

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: