Question
How can I extract the main query of an SSRS report?
ie. To troubleshoot or modify in SQL Server Management Studio or to send to someone else for assistance.
Answer
If you can access the SSRS portal and Report Builder, follow these steps.
-Browse to the report in question
-Click the ellipsis and choose 'edit in Report Builder'
-Click the plus next to the Datasets folder to expand it. In this example, there is only one dataset (query) named CRData.
-Double-click on 'CRData' to open the Dataset Properties window.
-The query is listed in the query window and can be copied and pasted in SSMS or wherever you need to paste it.
If you do not have access to Report Builder, follow these steps.
- Within the SSRS portal, browse to the report in question.
- Click the ellipse and choose 'Download'.
- Download to a place of your choosing.
- Navigate to the downloaded file, right-click, and chose 'edit with Notepad++' or whatever text editor tool you have.
- When the file opens, click [CTRL + F] and enter 'select' in the 'Find what' field, then click the Find Next button.
This will take you to the beginning of the SELECT statement of the query. You can copy the query and paste it where needed. There can be multiple datasets in a query. Make sure you are selecting the query you need, not just the query in the first [select] statement.
NOTE: SSRS reports are saved as XML. When opening a .rdl file via notepad ++, the greater than (>) and less than (<) symbols have changed to XML > and <