Sometimes we might be in a need to compare the changes in two versions of the same report.
We can observe the changes easily on the report if it is a color modification or something like this, What if , if the change is in terms of sizing ?
So to gather the reports background information and compare the changes in the two versions of the same report , we are going to make use of RDL files of the report in the default location : C:\Users\Sathya\Documents\Visual Studio 2010\Projects\Report1\Report1\Version1.rdl C:\Users\Sathya\Documents\Visual Studio 2010\Projects\Report1\Report1\Version2.rdl Two methods to get the XML content of the report :
1.)After the report is deployed,XML content of the report can be fetched from :
SELECT
content
FROM
ReportServer.dbo.catalog
2.)Bulk insert XML from RDL files in the default location : C:\Users\Sathya\Documents\Visual Studio 2010\Projects\Report1\Report1\Version1.rdl C:\Users\Sathya\Documents\Visual Studio 2010\Projects\Report1\Report1\Version2.rdl
In this example, we have followed method 2 . After getting the XML of the two versions of the report , using Xquery and nodes() method , we can easily share the values in the XML nodes and compare the values . Consider I have two versions of the same report as Version1.rdl and Version2.rdl Below are the screenshots of the two versions of same report : Version1 and Version2 report has textbox with below expression :
=
"User : "
+User!UserID+VBCRLF+
"ExecutionTime : "
+Globals!ExecutionTime
DECLARE
@Tmp
TABLE
(Id
INT
,
Name
VARCHAR
(20))
INSERT
1,
'Sathya'
2,
'Deepak'
*
WHERE
= @
USE AdventureWorks2012
GO
CREATE
PROCEDURE
RDL_Compare
@RDLFileName1 NVARCHAR(256),
--File path of the version1 of the RDL
@RDLFileName2 NVARCHAR(256)
--File path of the version2 of the RDL
AS
BEGIN
SET
NOCOUNT
ON
XACT_ABORT
TRY
/*Bulk inserting XML
from
RDL file */
@Query NVARCHAR(
MAX
)
#Version1_Rdl(XMLData XML)
#Version2_Rdl(XMLData XML)
TRANSACTION
@Query =
'INSERT INTO #Version1_Rdl(XMLData)
SELECT * FROM OPENROWSET(
BULK '
''
+@RDLFileName1+
',
SINGLE_BLOB) AS x;'
EXEC
(@Query)
'INSERT INTO #Version2_Rdl(XMLData)
+@RDLFileName2+
tmp1.ColumnHeader ColumnHeader_V1,
tmp1.ColumnName ColumnName_V1,
tmp1.ColumnValue ColumnValue_V1,
tmp2.ColumnHeader ColumnHeader_V2,
tmp2.ColumnName ColumnName_V2,
tmp2.ColumnValue ColumnValue_V2,
ISNULL
(tmp1.ColumnHeader,tmp2.ColumnHeader) Header1Compare,
(tmp1.ColumnName,tmp2.ColumnName) Header2Compare,
(tmp1.ColumnValue,tmp2.ColumnValue) ValueCompare
(
i.value(
'local-name(..)'
'varchar(max)'
) ColumnHeader,
'local-name(.)'
) ColumnName,
'.'
'varchar(MAX)'
) ColumnValue
#Version1_Rdl V1
CROSS
APPLY V1.XMLData.nodes(
'//*[text()]'
) x(i) ) tmp1
FULL
OUTER
JOIN
#Version2_Rdl V2
APPLY V2.XMLData.nodes(
) x(i)
) tmp2
tmp1.ColumnHeader = tmp2.ColumnHeader
AND
tmp1.ColumnName = tmp2.ColumnName
tmp1.ColumnValue = tmp2.ColumnValue
(tmp1.ColumnHeader
IS
NULL
tmp1.ColumnName
tmp1.ColumnValue
OR
(tmp2.ColumnHeader
tmp2.ColumnName
tmp2.ColumnValue
COMMIT
END
CATCH
@ERROR_MESSAGE NVARCHAR(256)
@ERROR_MESSAGE = ERROR_MESSAGE()
IF @@TRANCOUNT > 0
ROLLBACK
RAISERROR(@ERROR_MESSAGE,16,1)
'C:\Users\Sathya\Documents\Visual Studio 2010\Projects\Report1\Report1\Version1.rdl'
'C:\Users\Sathya\Documents\Visual Studio 2010\Projects\Report1\Report1\Version2.rdl'
Maheshkumar S Tiwari edited Original. Comment: corrected typo error and minor edit