- Oct 30, 2000
- 14,665
- 440
- 126
Trying to structure a CAML query with nested AND OR statements to retrieve data sets from a sharepoint list.
I'll give you an example of what I'm trying to retrieve back.
I have a list with several fields. This list contains incidents that have occurred at various locations. I would rather use a CAML query to retrieve the exact data set I need back than to use code to refine what I'm looking for. For example:
I want to retrieve data points back over a given date range for two different types of incidents at 2 or possibly 3 different locations.
Here is a sample list with filler data to use.
My List: (field names below)
DateOfIncident
TypeOfIncident
Description
Location
There are dozens of different types and dozens of locations. Say for example I want to return all incidents that are of type "theft" and of type "vandalism" for locations "A, C, and G."
I tried doing it this way.
I've tried changing out the AND and the OR statements around but can't quite figure it out. In the example above, the AND and OR statements are just there as I've been playing with them in different nested layouts to produce the correct data set I'm trying to retrieve but haven't figured it out yet. Any help out there?
I'll give you an example of what I'm trying to retrieve back.
I have a list with several fields. This list contains incidents that have occurred at various locations. I would rather use a CAML query to retrieve the exact data set I need back than to use code to refine what I'm looking for. For example:
I want to retrieve data points back over a given date range for two different types of incidents at 2 or possibly 3 different locations.
Here is a sample list with filler data to use.
My List: (field names below)
DateOfIncident
TypeOfIncident
Description
Location
There are dozens of different types and dozens of locations. Say for example I want to return all incidents that are of type "theft" and of type "vandalism" for locations "A, C, and G."
I tried doing it this way.
Code:
<Query>
<Where>
<Or>
<Or>
<And>
<Or>
<Eq>
<FieldRef Name='Type'/>
<Value Type='Text'>Theft</Value>
</Eq>
<Eq>
<FieldRef Name='Type'/>
<Value Type='Text'>Vandalism</Value>
</Eq>
</Or>
<Eq>
<FieldRef Name='Location'/>
<Value Type='Text'>A</Value>
</Eq>
</And>
<Eq>
<FieldRef Name='Location'/>
<Value Type='Text'>C</Value>
</Eq>
</Or>
<Eq>
<FieldRef Name='Location'/>
<Value Type='Text'>G</Value>
</Eq>
</Or>
</Where>
</Query>
I've tried changing out the AND and the OR statements around but can't quite figure it out. In the example above, the AND and OR statements are just there as I've been playing with them in different nested layouts to produce the correct data set I'm trying to retrieve but haven't figured it out yet. Any help out there?
Last edited:
