How to use SPSIteDataQuery to get all site collection list Having same column name?

537 views Asked by At

I am having one site collection that has two sub sites subSite1 and subSite2.

  • subSite1 Having List EMP_info with Column name Title and Dept.
  • subSite2 Having List DEPT_info with column name Title and Dept_ID.
  • I want to show List EMP_info and DEPT_info on RootSite Visual Web Part.
  • I implemented it By using SPSiteDataQuery writing two separate queries.
    Is it possible to have a single query? If yes, how to write Single query for that?

If there are 1000 sub site and 1000 list with same column name then how to get that 1000 list using single query.

1

There are 1 answers

0
Arjun On

You may use the below code to get the required result:

SpDataqry.Lists="<Lists ServerTemplate=\"107\"/>";
SpDataqry.ViewFields="><FieldRef Name=\"Title\"/><FieldRef Name=\"Priority\" Nullable=\"TRUE\" Type=\"Text\"/>";
SpDataqry.Query="<OrderBy><FieldRef Name=\"Title\"/></orderBy> ";
SpDataqry.Webs="<Webs Scope="\SiteCollection\" />";

List template 107- is used for Task Lists. You can get List Template Id for other lists Here

Webs scope is set to Site collection level to get data from root site and sub sites below it.