Have you ever needed to get a download of your Umbraco content nodes in a cross-tab query e.g. download contact form data from Doc2Form? Using Umbraco's Contour product makes this a breeze but what about older systems? Thankfully, it's not actually that difficult.
We have a contact us form on one of our sites which uses an old version of Doc2Form which emails the customer details of the enquiry. One benefit is it also saves it to the recycle bin as a document with the name: "RE: SYSTEM DATA: umbraco master root". With that in mind, we can use SQL Server's PIVOT functionality to pull the data out in a nicely formatted manner.
Firstly you'll need to know the id's of the document type's properties, there are numerous ways to do this:
1. Just look at the cmsPropertyData table for a couple of content nodes (I could spot the ones I was after fairly easily)
2. Query the cmsPropertyType table:
Find the contentTypeId of the document type -you can do this by hovering your mouse over the document type in the tree and checking out the status bar (you can see the contentTypeId in brackets in the bottom left -mine here is 1074):
Once you have the contentTypeId of the document type, you can then get the ids of all the properties you're after by replacing "xxx" with your property id in the following script:
SELECT * FROM dbo.cmsPropertyType WHERE contentTypeId = xxx
3. Get it from the source of the document type editor
An alternative way is to examine the HTML of the Document Type editor. If you view the source on the "Generic Properties" tab and scroll to the section you're interested in (there'll be a h2 with the same name) you will find a ul that has the class of "genericPropertyList".
Each li of that ul will have the relevant id as part of it's id e.g. for a section called "Enquiry Form" the id will be: "EnquiryFormContents_49" where "49" is the id we're interested in. You can see mine (49, 50, 51 and 52 below):
Once you have these ids to hand (mine were 49, 50, 51 and 52) you just need to update the code below and run against your Umbraco database:
contentNodeId As [Id],
 As [Name],
 As [Telephone],
 As [Email Address],
 As [Notes]
SELECT contentNodeId, propertytypeid, ISNULL(dataNvarchar, dataNtext) As [Value]
) As src
FOR propertytypeid in (, , , )
) aS pvt
WHERE  IS NOT NULL OR  IS NOT NULL
ORDER BY contentNodeId
That will then produce some lovely formatted data for you, my example above produced:
||Please contact me as soon as possible about your great site, thanks.
It's also possible to automate this entire script so you don't need to find out the property ids, I'll post that separately.