locked
how to write a caml query -------- RRS feed

  • Question

  • when a date is selected,  caml query should fetch items in a list such that , it should display items which are not updated till the selected date ... it should not display updated items of selected date.

    DNDR

    Wednesday, June 19, 2013 4:35 PM

Answers

  •    <Where>
          <Lt>
             <FieldRef Name="Modified" />
             <Value Type="DateTime">2013-06-19T12:00:00Z</Value>
          </Lt>
       </Where>

    This should help. You can also replace it with a variable (see below) in the required format.

    SPUtility.CreateISO8601DateTimeFromSystemDateTime(MyDate)

    Please mark as "Propose as Answer" or "Vote" as appropriate.


    Regards, Sagir R Kazi

    • Proposed as answer by santhoshv Wednesday, June 19, 2013 8:44 PM
    • Marked as answer by Emir Liu Thursday, June 27, 2013 2:35 AM
    Wednesday, June 19, 2013 4:47 PM
  • An easy way to test CAML queries is:

    1. Go to your list
    2. Create a list view that displays the data your are interested in
    3. Open SharePoint Designer, and open the site that contains your list
    4. Click on Lists and Libraries, then select your list
    5. In the Views section, click on the view you created to open it
    6. Have a look at the CAML query.

    As an example for displaying all documents created before a particular date:

    <Query>
    	<OrderBy>
    		<FieldRef Name="FileLeafRef"/>
    	</OrderBy>
    	<Where>
    		<Lt>
    			<FieldRef Name="Created"/>
    			<Value Type="DateTime">2013-06-19T00:00:00Z</Value>
    		</Lt>
    	</Where>
    </Query>


    Regards, Matthew
    MCPD | MCITP
    My Blog
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.

    I just added a webpart to the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here: Upload and Crop User Profile Photos

    • Proposed as answer by santhoshv Wednesday, June 19, 2013 8:43 PM
    • Marked as answer by Emir Liu Thursday, June 27, 2013 2:35 AM
    Wednesday, June 19, 2013 4:47 PM
  • Hello,

    Start using CAML builder to generate any query. Please read below blog to understand it and download CAML builder in your PC:

    http://www.codeproject.com/Articles/458008/CAML-Query-Builder

    Hope it could help


    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"

    Whenever you see a reply and if you think is helpful, click "Alternate TextVote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "Alternate TextMark As Answer

    Please feel free to unmark answer if does not resolves your problem.

    • Marked as answer by Emir Liu Thursday, June 27, 2013 2:35 AM
    Thursday, June 20, 2013 11:27 AM

All replies

  •    <Where>
          <Lt>
             <FieldRef Name="Modified" />
             <Value Type="DateTime">2013-06-19T12:00:00Z</Value>
          </Lt>
       </Where>

    This should help. You can also replace it with a variable (see below) in the required format.

    SPUtility.CreateISO8601DateTimeFromSystemDateTime(MyDate)

    Please mark as "Propose as Answer" or "Vote" as appropriate.


    Regards, Sagir R Kazi

    • Proposed as answer by santhoshv Wednesday, June 19, 2013 8:44 PM
    • Marked as answer by Emir Liu Thursday, June 27, 2013 2:35 AM
    Wednesday, June 19, 2013 4:47 PM
  • An easy way to test CAML queries is:

    1. Go to your list
    2. Create a list view that displays the data your are interested in
    3. Open SharePoint Designer, and open the site that contains your list
    4. Click on Lists and Libraries, then select your list
    5. In the Views section, click on the view you created to open it
    6. Have a look at the CAML query.

    As an example for displaying all documents created before a particular date:

    <Query>
    	<OrderBy>
    		<FieldRef Name="FileLeafRef"/>
    	</OrderBy>
    	<Where>
    		<Lt>
    			<FieldRef Name="Created"/>
    			<Value Type="DateTime">2013-06-19T00:00:00Z</Value>
    		</Lt>
    	</Where>
    </Query>


    Regards, Matthew
    MCPD | MCITP
    My Blog
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.

    I just added a webpart to the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here: Upload and Crop User Profile Photos

    • Proposed as answer by santhoshv Wednesday, June 19, 2013 8:43 PM
    • Marked as answer by Emir Liu Thursday, June 27, 2013 2:35 AM
    Wednesday, June 19, 2013 4:47 PM
  • i am writing in visual webpart

    there from tool box i ll drag a date ikon[design page]

    then when ever i select the date---- it should relate to modified date column in the sp list and display in grid view  --where the column which is not modified when the  date is selected....

    if todays date i select then it should display what all rows items  which are not modified till today


    DNDR

    Thursday, June 20, 2013 6:20 AM
  • Hello,

    Start using CAML builder to generate any query. Please read below blog to understand it and download CAML builder in your PC:

    http://www.codeproject.com/Articles/458008/CAML-Query-Builder

    Hope it could help


    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"

    Whenever you see a reply and if you think is helpful, click "Alternate TextVote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "Alternate TextMark As Answer

    Please feel free to unmark answer if does not resolves your problem.

    • Marked as answer by Emir Liu Thursday, June 27, 2013 2:35 AM
    Thursday, June 20, 2013 11:27 AM