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

So, here is some lines of code that i write to retrieve data from Sharepoint list using CAML query.

string qryCaml = string.Format(@"<Where>
                                  <And>
                                     <Eq>
                                        <FieldRef Name='{0}'/>
                                             <Value Type='Text'>{1}</Value>
                                     </Eq>
                                     <Eq>
                                         <FieldRef Name='{2}'/>
                                              <Value Type='Text'>{3}</Value>
                                     </Eq>
                                   </And>
                              </Where>", QueryFieldName1, QueryValue1, QueryFieldName2, QueryValue2);

As you can see in the code, I declare all the Value Type as 'Text'.

So, even though the column has a Value Type of Choice/Lookup, the code will still run the value type as Text, and things goes smoothly without any issues.

My questions are, is it better to specified the value type? and is there any performance difference between specifying the value type than just stated it as 'Text'(Maybe faster queries)?

I'm very new to Sharepoint and I want my code to be as dynamic as possible, that's why I put all the Value Type as Text.

Thank you.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You have several options for your type attribute in your value element. You can use Boolean, Choice, Currency, DateTime, Guid, Integer, Lookup, Note, Text, User. These type attributes are required, and can't be omitted.

As regards to performance, CAML itself is faster than say LINQ, which at first need to be converted to CAML and then query the database. But regarding your question on value type, I havn't noticed any performance diffences, nor have I read of any performance differences between different types. My experience tells me what really effects performance is the number of data being returned - which has the most impact. If you only need three rows, never query for a thousand as in query.RowLimit = 1000;.

SPQuery query = new SPQuery();
query.Query = "<Where>
                   <And>
                       <Eq>
                           <FieldRef Name='" + QueryFieldName1 + "'/>
                           <Value Type='Text'>" + QueryValue1 + "</Value>
                       </Eq>
                       <Eq>
                           <FieldRef Name='" + QueryFieldName2 + "'/>
                           <Value Type='Text'>" + QueryValue2 + "</Value>
                       </Eq>
                   </And>
               </Where>";
query.ViewFieldsOnly = true;
query.RowLimit = 3;

Another aspect on performance is the number of rows present in the list. It's faster to query a list of 1'000 elements than a list of 1'000'000 elements. Still, having the expected data type is never wrong, and if you do know the data type in the first place - why not use it.

Reference:

share|improve this answer
1  
Thanks man for the answer, suppose it's better to specified the Value Type rather than using 'Text'. –  kamal Jun 20 '13 at 6:50

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.