0

Follow up to this question: CAML is ordering by content type even though not specified

I have the following query:

<Where>
<And>
    <Or>
        <Eq>
            <FieldRef Name='_ModerationStatus' />
            <Value Type='ModStat'>0</Value>
        </Eq>
        <BeginsWith>
            <FieldRef Name='ContentTypeId' />
            <Value Type='ContentTypeId'>0x0120</Value>
        </BeginsWith>
    </Or>
    <And>
        <Geq>
            <FieldRef Name='Number' />
            <Value Type='Lookup'>0</Value>
        </Geq>
        <Neq>
            <FieldRef Name='ID' />
            <Value Type='Counter'>0</Value>
        </Neq>
    </And>
</And>
</Where>
<OrderBy>
     <FieldRef Name='NumberOf' LookupId='True' />
</OrderBy>
<GroupBy Collapse='True'>
    <FieldRef Name='NumberOf' />
</GroupBy>

It works well, however not every list item has a value for the column 'NumberOf', so when my results are returned, with the numbers grouped at the bottom of the results, like this:

enter image description here

Is it possible to have the opposite, where the ordered 'NumberOf' column with numbers are first (ie. 2,3,5) and null values afterwards?

2 Answers 2

1

Try changing your OrderBy to Descending:

<OrderBy>
  <FieldRef Name='NumberOf' LookupId='True' Ascending='False' />
</OrderBy>
2
  • if you put more details about it really great.
    – Waqas Sarwar MVP
    Jun 11, 2014 at 21:05
  • This works, but the numbers would be in descending order. I essentially would like to have the Order By clause return the data so that the 'null' values in the 'NumberOf' column are after the 'not-null' values. Jun 12, 2014 at 13:16
0

I think the best you can do is to order it by the NumberOf field descending (Ascending='False'), so you'd have 5, 3, 2, null. In either case, you'll need logic after calling this query to resort the result set to meet your needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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