How to: troubleshoot an empty SPListItemCollection (CAML Query)

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.

MGR: the Intelogist

About MGR: the Intelogist

SharePoint Server developer, turned Sitefinity developer, turned Angular developer, turned SharePoint Online consultant, turned Unily consultant, turned O365 consultant... Never a dull moment!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

This site uses Akismet to reduce spam. Learn how your comment data is processed.