none
Filter data for SPListItemCollection

    Question

  • Hello 

    i have a one list in that i have two fields Document No and Date , i need to query based on the condition (For each document no i need fetch latest added date item )

    am using this one

     query.Query = @"<Query><Where><Eq>

                                   <FieldRef Name='S.No' />,
                                     <Value Type='Text'>" + oSPListItem["Document No"].ToString() +
                                                          "</Value></Eq></Where><OrderBy><FieldRef Name='Date' Ascending='False' /></OrderBy></Query>";


    Praveen

    Thursday, May 03, 2012 6:04 AM

Answers

  • Hello, 

    As said by Aviw you can't made this kind of query (no distinct in caml...)

    I just wanted to say that in your query, you must remove the "query" tag 

    instead of

    query.Query = @"<Query><Where><Eq>
                                   <FieldRef Name='S.No' />,
                                     <Value Type='Text'>" + oSPListItem["Document No"].ToString() +
                                                          "</Value></Eq></Where><OrderBy><FieldRef Name='Date' Ascending='False' /></OrderBy></Query>";

    having this

    query.Query = @"<Where><Eq>
                                   <FieldRef Name='S.No' />,
                                     <Value Type='Text'>" + oSPListItem["Document No"].ToString() +
                                                          "</Value></Eq></Where><OrderBy><FieldRef Name='Date' Ascending='False' /></OrderBy>";

    It won't solve your query here but it's something you need to remember


    Best regards, Christopher.
    Blog | Mail

    Thursday, May 03, 2012 7:26 AM
  • Hello!

    Unfortunately, you can't do that with CAML.

    You may use LINQ, or GetDataTable(), if applicable.


    My contributions: SharePoint 2010 Solution Installer

    Thursday, May 03, 2012 7:19 AM

All replies

  • Hello!

    Unfortunately, you can't do that with CAML.

    You may use LINQ, or GetDataTable(), if applicable.


    My contributions: SharePoint 2010 Solution Installer

    Thursday, May 03, 2012 7:19 AM
  • Hello, 

    As said by Aviw you can't made this kind of query (no distinct in caml...)

    I just wanted to say that in your query, you must remove the "query" tag 

    instead of

    query.Query = @"<Query><Where><Eq>
                                   <FieldRef Name='S.No' />,
                                     <Value Type='Text'>" + oSPListItem["Document No"].ToString() +
                                                          "</Value></Eq></Where><OrderBy><FieldRef Name='Date' Ascending='False' /></OrderBy></Query>";

    having this

    query.Query = @"<Where><Eq>
                                   <FieldRef Name='S.No' />,
                                     <Value Type='Text'>" + oSPListItem["Document No"].ToString() +
                                                          "</Value></Eq></Where><OrderBy><FieldRef Name='Date' Ascending='False' /></OrderBy>";

    It won't solve your query here but it's something you need to remember


    Best regards, Christopher.
    Blog | Mail

    Thursday, May 03, 2012 7:26 AM