U2U - CAML Query Builder
A time ago I need to write a SPQuery to query a List. I tested my query with the CAML Query Builder by Karine Bosch - U2U. After testing it I put the following query into my code like this:
SPList list = GetMyList();
SPQuery query = new SPQuery();
query.Query = “<Query><Where><Eq><FieldRef Name=’Title’/><Value Type=’Text’>TEST</Value></Eq></Where></Query>”;
list.GetItems(query);
The code above always return all items in the list. So I start looking at the query, after a few minutes I saw that I had set the Query property of the SPQuery object, so I had to remove <Query> and </Query> from my query. Like this:
query.Query = “<Where><Eq><FieldRef Name=’Title’/><Value Type=’Text’>TEST</Value></Eq></Where>”;
Otherwise the query is ignored and therefore all items from the list are returned.
February 11th, 2009 at 23:26
Yeah, that’s a mistake a lot of people make
Some time ago I stumbled on a similar issue. I created custom alerts, by setting the Filter property of an SPAlert instance. It turned out the CAML query that you have to use in that case is yet another variant: the “Where” tag is replaced by the “Query” tag. And advanced field types, like “Lookup” or even your own custom field types cannot be used. You can only use basic types… Really weird.