Rolling Up Blog Posts
I was recently presented with the following scenario: As part of the creation of a SharePoint dashboard, my business users are interested in seeing the number of blog comments and their current status by blog.
Our blogs are contained as subsites of a site called Blog Central which reside in a site collection called “Public.” The dashboard resides in a separate site collection. Our site collections contain individual content databases.
As a former developer, my initial response is to find an out of the box solution wherever possible.
- A content query web part wouldn’t suffice as its scope is limited to the current site collection
- Adding a new data connection in SP Designer to hook up to a dataview web part (DVWP) won’t work because the lists and libraries (not the web services) are also limited to the current site collection. These can be combined to recursively roll up content in the current site collection however.
I ended up querying the content database directly and presenting that through the DVWP. So, in SP Designer I created a new Database Connection. 
Browsing to the content database for the Public site collection I wrote the following query in order to retrieve the correct data:
SELECT Webs.Title,
CASE UserData.tp_ModerationStatus
WHEN 0 THEN ‘Approved’
WHEN 1 THEN ‘Rejected’
WHEN 2 THEN ‘Pending’
END AS Status,
COUNT(*) AS Total
FROM AllLists INNER JOIN
Webs ON AllLists.tp_WebId = Webs.Id INNER JOIN
UserData ON AllLists.tp_ID = UserData.tp_ListId
WHERE (AllLists.tp_Title = ‘comments’) AND
(Webs.FullUrl LIKE ‘%blogcentral%’)
GROUP BY UserData.tp_ModerationStatus, Webs.Title
ORDER BY Webs.Title, UserData.tp_ModerationStatus
I then conditionally formatted the DVWP to show different colours based on status and done.

If there is a better way to do this, using CAML or some other method, please let me know and I will share it.
Popularity: 4% [?]
2 comments »
Copy link for RSS feed for comments on this post or for TrackBack URI
Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
That isn’t really recommended.
To do cross site collection data aggregation, you need a tool like lightning tools lightning conductor web part,http://www.lightningtools.com/pages/lightning-conductor-web-part.aspx.
Speaking with some other Sharepoint people, we would highly advise to get rid of that query as directly querying the content databases is not recommended. Generally speaking it will take you out of support if you are querying the DBs directly, it is recommended to do it through the object model or web services.
Reply to eric
Comment by eric
— September 3, 2009 @ 6:10 am
Just to clarify for any future references: Reading database content does NOT void warrenty/microsoft support agreements. Only modification of the databases, or their content does.
It is not recommended for a variety of reasons (if the schema, or structure changes in a Microsoft Update or Release then the query would no longer be reliable), but often can still be benificial. Many third party components and especially reporting solutions run queries on databases all the time. Since this is also a reporting solution I see no real issues with executing it like this.
A custom developed component, third party tool like lightning tools, or SharePoint search might have also been viable alternatives.
Just thought I would clarify Microsoft’s support stance and offer my two cents.
Hope this helps,
Richard Harbridge
Reply to Richard Harbridge
Comment by Richard Harbridge
— September 8, 2009 @ 5:41 am