Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Way to View SQL Query (ies) Generated by SSRS Reports?

Is there a simple way to view the SQL Queries actually generated by SSRS other than running profile traces to capture them?

Is there some way from within the BIDS editor to see this?

like image 401
DavidStein Avatar asked Aug 09 '10 14:08

DavidStein


3 Answers

You could run something like the below against your SSRS report server. You will be able to see the sql that is being execute by the report datasets.

;WITH XMLNAMESPACES (
    DEFAULT 'http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition',
    'http://schemas.microsoft.com/SQLServer/reporting/reportdesigner' AS rd
),
ReportData AS
(
    SELECT name ReportName
           , x.value('CommandType[1]', 'VARCHAR(50)') AS CommandType
           , x.value('CommandText[1]','VARCHAR(8000)') AS CommandText
           , x.value('DataSourceName[1]','VARCHAR(50)') AS DataSource
    FROM (SELECT  name
                  , CAST(CAST(content AS VARBINARY(MAX)) AS XML) AS reportXML
            FROM  ReportServer.dbo.Catalog
            WHERE content IS NOT NULL
                  AND type != 3) a
                  CROSS APPLY reportXML.nodes('/Report/DataSets/DataSet/Query') r(x)
)

SELECT *
FROM ReportData
like image 193
Mark Avatar answered Sep 17 '22 15:09

Mark


In short, no. There is no good workaround. However, for development I generally created a test query alongside my work in SSRS. I would edit this inside Management Studio and then just paste the values back into BIDS. Assuming two parameters named "StudentID" and "TeacherID", the query looked like:

DECLARE @StudentID int
DECLARE @TeacherID int

SELECT @StudentID = StudentID FROM Students WHERE StudentName LIKE 'John Doe'
SELECT @TeacherID = TeacherID FROM Teachers WHERE TeacherName LIKE 'Mr. Jones'

-- PASTE IN QUERY FROM BIDS BELOW

This allowed me to use real text values from the drop-down parameter lists and simply paste in my query. Then I could optimize the query in Management Studio and then paste it back into BIDS when I was happy with the result.

like image 45
Aaron D Avatar answered Sep 16 '22 15:09

Aaron D


What I normally do is run SQL Profiler when I run the report and pull the query out of it with the parameters.

like image 45
Umar Avatar answered Sep 18 '22 15:09

Umar