Company      |       Articles & Research      |      Services      |      Software      |      Contact

SPQuery Based Joins In SharePoint 2010

While working with a client today on some SharePoint 2010 code, the requirement can up to do some query based joins. I hadn't done this before in SP 2010, but it's pretty sweet. The only way I have gotten around it in previous versions was converting the list data into data tables and then working with it in that format. Natively working with it is a whole lot less code, whole lot less complicated too. Even for permanent join type stuff, you can use projected fields which is really nice.

So, what's it look like? Consider the following snippet:

XML:
  1. <View>
  2. <ViewFields>
  3. <FieldRef Name="ID_X" />
  4. <FieldRef Name="ID"/>
  5. <FieldRef Name="Title"/>
  6. </ViewFields>
  7. <Joins>
  8. <Join Type="LEFT" ListAlias="Test">
  9. <Eq>
  10. <FieldRef Name="ID_List_X" RefType="ID" />
  11. <FieldRef List="X" Name="ID" />
  12. </Eq>
  13. </Join>
  14. </Joins>
  15. <ProjectedFields>
  16. <Field Name="ID_X" Type="Lookup" List="X" ShowField="ID" />
  17. </ProjectedFields>
  18. </View>

Pretty easy!

share save 171 16 SPQuery Based Joins In SharePoint 2010

Related posts:

  1. SPView Field Comparison
  2. Disable Datasheet View If You Have Super Large Lists In SharePoint 2010
  3. SharePoint 2010 Lookup Columns and Performance Considerations
  4. SharePoint ECMAScript (Client Object Model) Empty List Helper
  5. Get SharePoint List View Items

2 Comments »

  1. [...] SPQuery Based Joins In SharePoint 2010 [...]

    Pingback by SharePoint 2010: Recopilatorio de enlaces interesantes (VII! - Blog del CIIN) — May 1, 2010 @ 12:10 pm

  2. you can usa LINQ to do joins, it’s easier IMHO, CAML can be used as a filter

    Comment by decatec — June 5, 2010 @ 2:38 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment