SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently writing some CAML Query for a QueryOverride in one of my Content Query Web Parts as I'm in need of multiple "Sort by" fields.

My issue is that one of the additional fields that I need sorting on may contain null values which make the query ignore the rows which has a null value and only performs the sort on rows which has a legitimate value.

My CAML Query so far

    <FieldRef Name="ArticleStartDate" Ascending="False" />
    <FieldRef Name="ArticlePriority" Ascending="True" />
            <FieldRef Name="FilterMM" />
            <Value Type="TaxonomyFieldType">Company news</Value>
                <FieldRef Name="ArticleStartDate" />
                <Value Type="DateTime"><Today /></Value>
                <FieldRef Name="_EndDate" />
                <Value Type="DateTime"><Today /></Value>

ArticlePriority is the troublemaker, as not all news have a priority set as they are less important than others which has priority 1,2,3 etc. meaning they should at all times be AFTER the ones with set priorities.

I tried adding Nullable="True" to it as I thought that might help but no luck.

Any ideas?

share|improve this question
up vote 3 down vote accepted

If ArticlePriority is a choice column then null values will be sorted before the ones with values.

One solution could be to create a hidden calculated column with the formular something like =IF(ArticlePriority=0,9999,ArticlePriority) and then order by that column

share|improve this answer
It's unfortunately not a choice column, it's a number column as the priorities have to be unique values in order to prevent multiple articles having the same priority. – Daniel Ziga Jan 10 '13 at 13:40
Then use the formular =IF(ISNUMBER(ArticlePriority),ArticlePriority,999999) – Per Jakobsen Jan 10 '13 at 13:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.