CAML JOINS using SharePoint

5.3k Views Asked by At

Assume that there are Emp and Dept tables.

Emp Table has

EmpID
FirstName
LastName
DeptName
Email

Dept table has

DeptID
DeptName

i have to display all the employee details based on DeptName using CAML query. Can some one share CAML JOINS example for this scenario.

Thank you

2

There are 2 best solutions below

0
On

1) Are you on SP 2007 or SP 2010 2)On easy approach is create a querystring in SP designer and then show the employee details based on the query string from the URL If doesn't solve your proble then yiu have to take Kyle advice and do it from code and LINQ could be a good way to go

0
On

Check this approach very easy to join as many list as you want: Link

cawl_QueryBuilder cawl = new cawl_QueryBuilder();
cawl.Select("Users_Title");
cawl.Select("Users_Age");
cawl.Select("Users_Sex");
cawl.Select("CarBrand");
cawl.Join("UsersList";"OwnerColumn");
cawl.Get('UserCarsList');

StringBuilder Result = new StringBuilder();
foreach (SPListItem item in cawl.ListItemCollection())
{
  Result.Append(item["Users_Title"].ToString() +
                 item["Users_Age"].ToString() +
                 item["Users_Sex"].ToString() +
                 item["CarBrand"].ToString());

}
Label1.Text = Result .ToString();