Example of a CAML Query

Sep 7, 2011 at 12:48 PM

I spent a couple of days banging my head on the desk while trying to get the basic CAML query working correctly. I finally did, and thought I'd post it here in case it helps anyone else.

<Where><Eq><FieldRef Name="Scope"></FieldRef><Value Type="Text">Project</Value></Eq></Where>

This query goes into the box exactly as above, and filters the given list so that items will only appear if the field called "Scope" has a value of "Project". Two things were killing my query, apparently - I didn't have the closing tag for FieldRef, and my Value Type was "Lookup" instead of "Text". As I understand it, anytime you're doing an exact match to the value of a field (even number, date, etc.) that Value Type should be Text. I'm no expert, though, so you may want to research that on your own if you're still having issues. Also, I originally had opening and closing <Query> tags, which were duplicating in the XLST since the code already adds those when the page is rendered.

Anyway, hope it helps.