Join SPQuery in two list
List 1 "Posts", fields
Title body #comments modified
in this list #comments fields is look up from another list Comments:
List 2 "Comments", fields
title body comments post tilte modified
in this list post "title" field is look up from list 1.
Now I have to form a join SPQuery to get a comments list modified field.
SPList listFaculty = web.Lists["Posts"];
SPQuery query = new SPQuery();
query.Query = "<where></where>";
query.Joins = "<join Type='Left' ListAlias='Comments'>" + "<eq><fieldref Name='Title' RefType='ID' />" + "<fieldref List='Comments1' Name='ID'
/></eq></join>";
query.ProjectedFields = "<field Name='Modified1' Type='Lookup' List='Comments1' ShowField='Modified'/>";
query.ViewFields = "<fieldref Name='Modified1' />";
SPListItemCollection lists = listFaculty.GetItems(query);
I'm getting error
Value does not fall within the range
What am I doing wrong?
Hello,
Can you do 2 things,
1), pay attention , CAML is case sensitive, you should change your tags (Eq,Join,Field,FieldRef)
2) If you don't specify a query, just don't do it (remove the query.Query = "<where></where>"; line)
If it still doesn't work, take a look at this post, it could help you
http://blogs.msdn.com/b/kaevans/archive/2012/01/20/sharepoint-2010-caml-list-joins.aspx
Best regards, Christopher.
Blog |
Mail
Please remember to click "Mark As Answer" if a post solves your problem or
"Vote As Helpful" if it was useful.
Why mark as answer?
Similar Messages
-
Join two list of integer type field using CAML query
Hi
As i am struggling in Join two sharepoint list (Roles and Emplyees). As there is no lookup columns and lists are already existing and have almost 3000 + recodrs. As a part of enhancement work need to join these list. List structure is some thing as follows:
Roles :
ID Title
1 Project Manager
2 Business Analyst
3 Developer
Employees :
Name Role
1 James 1
2 Petar 3
3 John 2
Output should be like as follows:
Name Role
1 James Project Manager
2 Petar Developer
3 John Developer
So please suggest, if the joining can be done other than lookup columns through the CAML query.
Akhilesh RaoFollow below CAML query to add joins between two lists.
SPList list = SPContext.Current.Site.RootWeb.Lists["Employees"];
SPQuery query = new SPQuery();
query.Joins = @" <Join Type="INNER" ListAlias="Roles">
<Eq>
<FieldRef Name="Employees" RefType="Role" />
<FieldRef List="Roles" Name="ID" />
</Eq>
</Join>";
query.ProjectedFields = @" <Field Name="RoleName" Type="Lookup" List="Roles" ShowField="Title">";
query.ViewFields = @ "<FieldRef Name="Title">
<FieldRef Name="RoleName"> ";
SPListItemCollection result = tablea.GetItems(query);
Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer :) -
How to join two lists and display the results in datasheet view.?
hello,
i have two lists that i would like to join, i know a method that has been described in the link below
http://www.codeproject.com/Articles/194252/How-to-Link-Two-Lists-and-Create-a-Combined-Ciew-i
however, here the data view is only limited to 30 rows and my resultant list is huge. I would like to know if there is a possibility to view the resultant list in a data sheet view ?I don't believe you can use the OOTB Datasheet view when joining lists. However, you should be able to increase your limit from 30 items to as many as you need (that doesn't trip the threshold set in Central Admin).
Dimitri Ayrapetov (MCSE: SharePoint) -
Join two list with condition using caml query in SharePoint 2013 with client object model
Hi,
Want to join two list to get all fields from both list.
Am new to sharepoint and sharepoint 2013. Am working in sharepoint 2013 online apps. Am using context.executeQueryasync to load list and get items from list. Am able to get items from single list with caml query, but not able to get both list field values
with joins. I did lot of surfing..but not..
Below is my code..
ListName1 : "AssignedTasks"
ListName2 : "Tasks"
var assignedQueryTest = "<View><Joins><Join Type='INNER' ListAlias='Tasks'><Eq><FieldRef Name='TaskId' RefType='Id'/><FieldRef List='Tasks' Name='ID' /></Eq></Join></Joins>"
+ "<ViewFields><FieldRef Name='TitleValue' /><FieldRef Name='ActionItemsValue' /></ViewFields>"
+ "<ProjectedFields>"
+ "<Field Name='TitleValue' Type='Lookup' List='Tasks' ShowField='Title' /><Field Name='ActionItemsValue' Type='Lookup' List='Tasks' ShowField='ActionItems' />"
+ "</ProjectedFields>"
+ "</View>";
var web = context.get_web();
var list = web.get_lists().getByTitle("AssingedTasks");
var myQuery = new SP.CamlQuery();
myQuery.set_viewXml(assignedQueryTest);
var myItems = list.getItems(myQuery, "Include(TitleValue,ActionItemsValue)");
context.load(myItems);
context.executeQueryAsync(function () { if(myItems.get_count()>0){....}
}, errorCallback);
Here am able to get "AssignedTasks" list field values but not able to get "Tasks" list field values.
Can you please help me to resolve the issue. Or new idea for join. I have add the condition also in the query.
If anybody have good sample, please provide.
Thanks,
Pariventhan
Pariventhan.SHi Pariventhan,
I don't know about join but I have a workaround of this problem.
Declare one variable (itemcollection) globally. Load all the items "AssignedTasks" using context.load.
In the success method call another CAML query using <IN> tag of the ID of the items from the second list (Assuming you have look-up column of the ID of the first list to the second list).
If this is not clear to you then please let me know. If possible then I can provide code sample.
Thanks,
Aniruddha -
Hi,
Let's say I have a class Car
public class Car{
private int id;
private String make;
private String model;
//getters and setters
}Now I'm going to some db and fill a List<Car>,
List<Car> results1 = getCarsFromDB(String someCriteria);and I do the same but this time I'm going to another db,
List<Car> results2 = getCarsFromAnotherDB(String someCriteria);What I want is to create a list with the two results lists. Using contains method from List doesn't work because the objects are different although the have the same data. Is there a simple way of joining this? (in my example, two objects are equal if they have the same idthanks in advance,
Manuel Leiriaok, I have now an equals and hashCode method in my
Car but I can't see how the Collections.addAll can
help me! When joining the two lists in a resultlist,
at some point I must compare the Car objects. Am I
wrong?
thanks,
Manuel leiriaso if I understand you, you're trying to merge 2
collections, and avoid duplicates? sounds like a job
for Sets, then!yes, I've changed my final list to a set. It's better
thanks,
Manuel Leiria -
The order doesn't work in my view with join between two lists. And now?
Hi,
I work with sharepoint 2010.
I did the join between two list follow this
post.
I did it and everything is ok, but the order doesn't work.
What can be it?
Thanks
K2rto'4 - Analista Sharepoint
"Hoje melhor do que ontem, amanhã melhor do que hoje!" 改 善Hi,
I've two lists in my view with join. The list A and the list B.
I'm ordering the view with the column list A.
The column list A it's a column for type lookup to list B's column.
In my view i'm ordering with the column list A of type lookup.
The view with join is not ordering in order growing.
I want the view will be ordering by order growing.
Do you understood?
Hugs
K2rto'4 - Analista Sharepoint
"Hoje melhor do que ontem, amanhã melhor do que hoje!" 改 善 -
Export to Excel - two lists into 1 Excel table
Hello SharePoint experts,
I have two lists with the exact same columns of data. The reason I have two lists is because they each represent a single year of data where the list contains 5,000+ items. We found we had
to "archive" old year items into a new list, otherwise we were not able to appropriately export to Excel (it wouldn't work) as well as make updates to the InfoPath from when the count was too high.
These lists are exported into Excel to leverage pivot tables and run metrics based on the data in the lists. I can bring both data connections into the same Excel file, but I am not sure if
there is a way to merge the lists so I can simply apply a filter to the pivot tables to select the appropriate year.
Any input is greatly appreciated.
Mark G.
MGIf you have both data connection files, I think you just need to make a join/merge. I think this may help:
http://office.microsoft.com/en-us/excel-help/combine-data-from-multiple-data-sources-HA103993145.aspx
Andy Wessendorf SharePoint Developer II | Rackspace [email protected] -
How to add two list in one frame using REUSE_ALV_LIST_DISPLAY
Hi,
I want to display two list in single output by calling FM 'REUSE_ALV_LIST_DISPLAY' twice.
I saw one topic posted by Arunava Das as 'ALV Problem' but didn't get the steps to do that.
Here is his way of doing that "What I have done is gone for the append ALV approach wher I have added the END_OF_LIST Event for the Fisrt reprt and in the Corresponding FORM Routine I have added another made another cALL to the REUSE_ALV_LIST DISPLAY FM with the other table."
I would be grateful if someone can help me out.Hi Ashish,
The way you have tried i.e. calling the second list in the END_OF_LIST event of first list and like wise that is the correct way of doing it.
Using this way you can display multiple lists. In the event END_OF_LIST by using a global variable G_COUNTER. the value of which you increment for each list and based on that counter you call different lists in the END_OF_LIST event.
case G_COUNTER.
when 1. perform call_first_list.
when 2. perform call_second_list.
when 3. perform call_third_list.
endcase.
Hope this answers your query
regards,
Satyadev Dutta -
Get data from two list simultaneously using REST
Is it possible to query two list in the same time?
url: http://sites.com/url/_api/web/lists/GetByTitle(‘List1')
url: http://sites.com/url/_api/web/lists/GetByTitle(‘List1' and 'List2')
Thanks in advanceHi ,
By default SharePoint doesn't provide this kind of rest service or server object model api to retrieve the specified multiple lists once, it could only get all lists or one specified list one time.
you may query twice to get two lists as a workaround.
http://msdn.microsoft.com/en-us/library/office/fp142380(v=office.15).aspx
http://msdn.microsoft.com/en-us/library/jj246453.aspx
Thanks
Daniel Yang
TechNet Community Support -
How to merge alphabetically two lists through a rational solution?
Have two lists of captions it two languages and need to merge alphabetically, but this solution is very poor.
(list x)
Palacio Imperial, Barcelona, 2012
Cementerio, 2009
(list y)
Imperial Palace
Cemetery
to obtain:
Palacio Imperial, Barcelona, 2012
Imperial Palace
Cementerio, 2009
Cemetery
One method very naive:
· number the lists
· convert numbering to text
· in list y add a constant to sort in order:
1. Palacio Imperial, Barcelona, 2012
2. Cementerio, 2009
1a. Imperial Palace
2a. Cemetery
and sort:
1. Palacio Imperial, Barcelona, 2012
1a. Imperial Palace
2. Cementerio, 2009
2a. Cemetery
delete the code:
Palacio Imperial, Barcelona, 2012
Imperial Palace
Cementerio, 2009
Cemetery
(italics are not required)
Thanks.Camilo,
Another more original way with QuicKeys! [I love this little soft for a long time!] Only 1 click!
For it, you need to use a different paragraph style for each list [eg. List1_Style and List2_Style].
Eg, our list:
A1
A2
A3
A4
B1
B2
B3
B4
Search: (?<=\r)(.+\r)+
Search format: List1_Style
Search-Research Windows must be open into ID.
Shorcut in QuicKeys:
1rst research
1/ Click on the button: Search (actived - in blue)
A2
A3
A4
is selected.
2/ Cut it (shortcut: Apple+X)
3/ Down arrow (of the keyboard)
4/ Copy it
We obtain:
A1
B1
A2
A3
A4
B2
B3
B4
2nd research
1/ Click on the button: Search (actived - in blue)
A3
A4
is selected.
2/ Cut it (shortcut: Apple+X)
3/ Down arrow (of the keyboard)
4/ Copy it
We obtain:
A1
B1
A2
B2
A3
A4
B3
B4
3rd research
1/ Click on the button: Search (actived - in blue)
A4
is selected.
2/ Cut it (shortcut: Apple+X)
3/ Down arrow (of the keyboard)
4/ Copy it
We obtain:
A1
B1
A2
B2
A3
B3
A4
B4
The research stops automatically.
The last work (after this test) is to create a loop in QuicKeys to run the steps 1/-2/-3/-4/ as many times as necessary until the end of the process. -
Drag and Drop between two list boxes
Hi all
I am working over Drag and Drop .. i have to implement Drag and Drop between two list boxes .. both list box exist in same page ..each list box have number of rows.. please give me some idea ... as i am new for JSP and Servlet...
Thanks in advance
Regards
VaibhavHi all
I am working over Drag and Drop .. i have to
implement Drag and Drop between two list boxes ..
both list box exist in same page ..each list box have
number of rows.. please give me some idea ... as i am
new for JSP and Servlet...
Something close to what you are looking for is Select Mover in Coldtags suite:
http://www.servletsuite.com/jsp.htm -
How we calculate the date difference between two list in SharePoint 2010
Hi friend's....I have two list first is list1. In this list i have two coulmn start_date and End_date. In second list2 i have two column HolidayName and Holiday_date. Now i want two find the number of day in list1 Excluding Weekend and Holiday_date(that
column from list2). How i will do ..? Please help me dosto..Thanks for reply...
I have done the date difference in list1. But i want to Exclude the Holiday_date form list2.
I have list1 - Start_date , End_date, Number_of_day(Exclude weekend and Holiday_date between Start_date and End_date )
list2 - HolidayName, Holiday_date
Now how i will calculate the Number_of_day in first list. -
Pull information from two list
I have two list setup like the below sample.
List A List B
NAME NUMBER.
ACCOUNT NODE#
Eric 1234
nn-1234-aa 7
I need a way that i can match account in list B with number in list A and pull node# with it.
I would like to get this¦
NAME. NUMBER.
NODE#
Eric 1234
7
Is this possible and if so any help would be great.
Thanks,
Eric Ray
EricI have two list setup like the below sample.
List A List B
NAME NUMBER
ACCOUNT NODE#
Eric 1234
nn-1234-aa 7
I need a way that i can match account in list B with number in list A and pull node# with it.
I would like to get this¦
NAME NUMBER
NODE#
Eric 1234
7
Is this possible and if so any help would be great.
Thanks,
Eric Ray
Eric -
Linking two lists to create a Data Source but cannot add web part to page in SharePoint designer
All;
I created a new data source by linking two lists which created a linked Data Source. I now want to access that linked data source via insertion of a Data Source control on a web part page.
What I find is, both DATA SOURCE and DATA VIEW are inactive and unselectable.
Is there any way to get this functionality going?
Thx
Larry PexterHi Larry,
Since it is a coding UI, we need to put cursor into appropriate place so we can insert data view web part, i.e. the coding which represents the web part in to the whole coding part.
As I tested in my envrionment, if you put cursor between <ZoneTemplate> and </ZoneTemplate>, I cannot get the DATA view, even before </ZoneTemplate>. Please put it exactly before <ZoneTemplate>.
If you have modify the coding, please click save and test the issue again.
Regards,
Rebecca Tu
TechNet Community Support -
I need to know if it is possible to merge two lists using coldfusion. I have one list uploaded to the site then they want the ability to upload a second list with may have additional fields and/or different number of records. Need to know if this is possible, how to do it if it is, and how the two list will match up. Thanks in advance for the help.
Right, well in that case this isn't really anything to do with merging lists per se, hence the confusion I believe. Technically, you'd do this:
<cfset newData = fileOpen("c:\newlist.csv","read") />
<!--- Loop through your file, one line at a time --->
<cfloop condition="NOT fileIsEof(newData)">
<!--- Create a string of the line, this is a true list --->
<cfset thisLine = fileReadLine(newData) />
<!--- Get the elements of the list we want for the query --->
<cfset thisForename = listGetAt(thisLine,1) />
<cfset thisSurname = listGetAt(thisLine,2) />
<!--- Check if this person exists --->
<cfquery datasource/username/password name="qCheckExists">
SELECT id
FROM mytable
WHERE firstname = <cfqueryparam cfsqltype="cf_sql_varchar" value="#thisForename#" />
AND surname = <cfqueryparam cfsqltype="cf_sql_varchar" value="#thisSurname"#" />
</cfquery>
<!--- If we found rows, update --->
<cfif qCheckExists.RECORDCOUNT eq 1 >
<cfquery datasource/username/password>
UPDATE mytable
SET forename = <listGetAt,thisLine, FIELD>,
surname = <listGetAt,thisLine, FIELD>,
address = <listGetAt,thisLine, FIELD>,
etc etc etc
WHERE id = qCheckExists.id
</cfquery>
<cfelseif qCheckExists.RECORDCOUNT >
<!--- here you found more than one matching row, up to you what to do --->
<cfelse>
<!--- here you didn't find a match, so do an insert --->
</cfif>
</cfloop>
<cfset fileClose(newData) />
That's how you'd do it on a technical level, the Business decisions are yours. What if it's John not Jon? What if it's Jonathan? That's not a programming problem, that's up to you to decide - I'm not sure we can help you there.
O.
Maybe you are looking for
-
Downpayment Processing as a Document Pricing Condition
Hi There, Through help.sap.com I was researching new functionality, and found the following documentation on processing Downpayments through pricing conditions. http://help.sap.com/erp2005_ehp_02/helpdata/en/46/27dcd449fc14dce10000000a155369/content.
-
2) they can all be maximized to the largest possible size, while 3) NOT forcing table columns larger than the screen width so that all the text in a column STAYS ON THE DAMNED SCREEN! Is there a way to do this (so far the add ons have come up lacking
-
Problem install Intermedia, web agent
Hi, I'm just installed the kit, but I have next errors... file: Error_log from [home_portal]\apache [date] [alert] mwm-00067: non-recoverable initialization or termination error [date] [alert] [client 10.1.0.40] Configuration not available to execute
-
Unable to found Bucket start date and bucket end date in OFSAA 6
Hi, How to find the Bucket start date and bucket end date in OFSAA 6. I found following tables to mapped to Dim_Result_Bucket but unable to found columns pointing to Bucket Start Date and Bucket End Date. Tables: fsi_income_simulation_buckets fsi_pr
-
How do I do a defrag? My machine is running slow and defragging always worked with Microsoft. Thanks in advance.