In a previous post, I talked about the SPQuery and the CAML query builder.
One common problem that you may face when working with these elements is that you may be getting an empty result set no matter how well you think you’re passing the built query into your SPQuery.
The things you will need to check if you’re always getting NO RESULTS into your collection are the following:
1. check that you are using the internal name of the column you are quering on
2. if you’re using a DateTime column, remember that quering against Date alone will not work. You need to include the “IncludeTimeValue=”TRUE” Type=”DateTime”” bit in your Value section. Like so:
<Where><Eq><FieldRef Name=”Modified” /><Value IncludeTimeValue=”TRUE” Type=”DateTime”>2012-05-31T17:45:35Z</Value></Eq></Where>
3. if you’re using the U2U CAML Query Builder, remember that it will NOT provide you with a result that you can use as is. You will NEED TO REMOVE the leading and trailing Query tags. The above was the correct, the following is what CAML Query Builder would have provided you with: <Query><Where><Eq><FieldRef Name=”internalFieldName” /><Value IncludeTimeValue=”TRUE” Type=”DateTime”>requestedDateAndTime</Value></Eq></Where></Query>
Hope this helps.