This blog is now obsolete. Go to scott.arbeitman.id.au for all new content.

Dynamics CRM 4: Discovering the SQL behind an "Advanced Find"

| Wednesday, November 26, 2008

Have you ever wanted to know exactly what SQL was generated by the advanced find? This question might just be because of shear curiosity, but the results of this query by also be the starting point for most sophisticated reports using SQL Server Reporting Services.

The process is straightforward. All you need is Dynamics CRM 4 and Excel 2007 (2003 should work similarly). [See update below for doing this without Excel]

Perform an advanced find  
Run the query, and export the results to Excel. Make sure you select "Dynamic Worksheet" although I'm pretty sure "Dynamic Pivot Table" will work image
In Excel, once you have data displayed (which might mean enabling data connections), go to the Data tab, and click "Connections" image
You should have a single connection called "Connection". Look the properties for this connection. image
Go to the definition tab. The command text contains the SQL behind the advanced find. image

This approach works with SharePoint lists as well. Using this technique with SharePoint list data helps you quickly determine the GUID of the list and the view you are using.

Update: Dynamics exports the data as an XML file, not a binary XSL file. Therefore, you can simply open the downloaded "Excel" file with a standard text editor and view the SQL within. 

0 comments: