CAML query syntax

Status
Not open for further replies.

williane

Ars Scholae Palatinae
1,493
I'm building a report that pulls from a SharePoint list. I'd prefer to avoid using filters as the list is many thousand records and I'd like to just pull what I need rather than pull it all and try to filter. The SQL equivalent of what I'm trying to achieve would be:

Code:
where EventDate between @StartDate and @EndDate 
and 
(category like '%cat1%' or
category like '%cat2%' or 
category like '%cat3%' or 
category like '%cat4%')

Here is what I have come up with but it doesn't seem to be working as expected.

Code:
<Query>
    <Where>
      <Or>
		<And>
			<Geq>
			  <FieldRef Name="EventDate" />
			  <Value Type="DateTime">
				<Parameter Name="StartDate" />
			  </Value>
			</Geq>
			<Leq>
			  <FieldRef Name="EventDate" />
			  <Value Type="DateTime">
				<Parameter Name="EndDate" />
			  </Value>
			</Leq>
		</And>
		<Or>
			<Contains>
				<FieldRef Name="category" />
				<Value Type="Text">cat1</Value>
			</Contains>
			<Or>
				<Contains>
					<FieldRef Name="category" />
					<Value Type="Text">cat2</Value>
				</Contains>
				<Or>
					<Contains>
						<FieldRef Name="category" />
						<Value Type="Text">cat3</Value>
					</Contains>
					<Contains>
						<FieldRef Name="category" />
						<Value Type="Text">cat4</Value>
					</Contains>
				</Or>
			</Or>
		</Or>
      </Or>
    </Where>
  </Query>

Once I pull the correct data, I can then group by category in the chart series, I'm just not having much luck getting exactly what I want. Open to other suggestions as well if I'm trying to put a square peg in a round hole. :eng101:
 

williane

Ars Scholae Palatinae
1,493
[url=http:/civis/viewtopic.php?p=26358631#p26358631:jyxltlzx said:
Nazgutek[/url]":jyxltlzx]Your outermost operator in the CAML is an <OR>, but judging by your SQL it should be an <AND>? (Disclaimer: I've never seen CAML before in my life)

Wow, yeah, looks like that was it. I knew it would be something small like that. Guess I just got jumbled looking at all those nested <or>s.
 
Status
Not open for further replies.