locked
SPQuery OrderBy is not working on custom Number field RRS feed

  • Question

  • I have one custom column named 'fhdr_Index' which is type of Number field.

    I want to get maximum number in this column so i have applied Order By with Ascending 'FALSE' and RowLimit =1 . But query is not working.

                        qry.Query =
                        @"   <Where>
                                <IsNotNull>
                                   <FieldRef Name='ID'/>
                                </IsNotNull>
                            </Where>
                               <OrderBy >
                                  <FieldRef  Name='fhdr_Index' Ascending='FALSE' />
                               </OrderBy>";
                        qry.RowLimit = 1;
                        SPListItemCollection listItems = spList.GetItems(qry);

    First item from list is return. And If i apply query on ID column rather then fhdr_Index column query is working. 


    Wednesday, March 22, 2017 7:06 AM

All replies

  • Make sure you have enabled indexing attribute to true for the custom field in the schema.

    <Field ID="{59956c56-30dd-4cb1-bf12-ef693b42679c}" Name="fhdr_Index" ... Indexed="TRUE">


    Cheers,
    My Blog

    Thursday, April 6, 2017 6:05 AM