Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm new in CAML. I try to learn it. I want to render a day's on ASP Calendar. Have got a list with 5 colums/fields:

 Kontrakt | Pracownik | Dzien | ID | Procenty
 --------------------------------------------

When I render tradicional it's geting too long. When It has got more then 1000 element's it's getting 4-5 secounds. I want make Query which only gives me a day's withouts another colums/fields. I mahe a Query, in U2U Query Builder, but it gives me back all fields, and only I want a dates.

<Query> <Where> <And> <Lt> <FieldRef Name='Dzien' /> <Value Type='DateTime'>[Today+30Day(s)]</Value> </Lt> <Gt> <FieldRef Name='Dzien' /> <Value Type='DateTime'>[Today-30Day(s)]</Value> </Gt> </And> </Where> </Query>  

How to make a Query with only one field Dzien. Please help

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Following is using SPQuery to return specific fields...

    SPQuery query = new SPQuery();
    query.Query = "<Where> <And> <Lt> <FieldRef Name='Dzien' /> <Value Type='DateTime'>[Today+30Day(s)]</Value> </Lt> <Gt> <FieldRef Name='Dzien' /> <Value Type='DateTime'>[Today-30Day(s)]</Value> </Gt> </And> </Where>"; // You can add some condition. Items returned by query
    query.ViewFields = String.Format("<FieldRef Name='{0}'/>", "Dzien"); //Fields returned by query

    SPListItemCollection itemCollection = myList.GetItems(query);

If you want multiple columns, you can specify adding more <FieldRef Name='fieldName' />

Also, for performance you can create Indexes on columns involved in Query for better performance:

enter image description here

enter image description here

enter image description here

You can read Indexing and Query Throttling here

share|improve this answer
add comment

Your Answer

 
discard

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.