Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Limit the result of CAML Query

Posted on 2010-08-31
5
Medium Priority
?
940 Views
Last Modified: 2013-12-17
I have a list in sharepoint that contains five columns. Is it possible to limit the result of the query to 3 columns only?
Example:

I have Firstname, Lastname, Middlename, Age, Gender. When I execute the query it only returns Firstname, Lastname, Middlename.
Is that possible to CAML query?
0
Comment
Question by:PagodNaUtak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
shahzadbux earned 1000 total points
ID: 33574347
have a look at this guide: http://sharepointmagazine.net/technical/development/writing-caml-queries-for-retrieving-list-items-from-a-sharepoint-list

quoted from the site:

"In cases you work with large lists it can be important to retrieve a subset of list items containing only the columns you need. In that case you will have to set the ViewFields property of the SPQuery object. You can do this by specifying all columns you want to see returned:

qry.ViewFields = "";
This will return the first name and the last name of the retrieved employees, but also the system fields like the ID and the Created date."
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 1000 total points
ID: 33574371
You should be able to filter the list of fields returned using the ViewFields property of the SPQuery object.

See here for details: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewfields.aspx
0
 
LVL 8

Author Comment

by:PagodNaUtak
ID: 33575229
qry.ViewFields = "<FieldRef Name='FirstName'  DisplayName='FIRSTNAME'/>
Is it possible to set the displayname of the column? I tried the above code but to no avail? Any ideas?
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 33575244
What are you trying to do with the output, display it directly or access it programmatically?
0
 
LVL 8

Author Comment

by:PagodNaUtak
ID: 33575302
I am binding it to gridview... see the code below...
  SPQuery query = new SPQuery();
                   query.Query = sb.ToString();
                   query.ViewFields = @"<FieldRef Name='ID'/><FieldRef Name='Title' />
                    <FieldRef Name='Position' /><FieldRef Name='Status' />
                    <FieldRef Name='DateApplied'/><FieldRef Name='InitialInterview'/>
                    <FieldRef Name='AptitudeExam'/><FieldRef Name='AptitudeScore'/>
                    <FieldRef Name='Essay'/><FieldRef Name='TechExamDate'/>
                    <FieldRef Name='Score'/><FieldRef Name='TechInterview'/>
                    <FieldRef Name='FinalInterview'/><FieldRef Name='JobOffer'/>
                    <FieldRef Name='CreatedDate' />";
                   
                   gdviewApplicants.DataSource = null;
                   gdviewApplicants.DataSource = listApplicants.GetItems(query).GetDataTable();

Open in new window

0

Featured Post

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question