Delete rdl files from SSRS report services

Before deleting report in report server



USE [ReportServer]

GO

--Replace NULL with keywords of the ReportManager's Report Path,

--if reports from any specific path are to be deleted

DECLARE @FilterReportPath AS VARCHAR(500) = NULL

--Replace NULL with the keyword matching the Report File Name,

--if any specific reports are to be deleted

DECLARE @FilterReportName AS VARCHAR(500) = 'List Report'

--Used to prepare the dynamic query

DECLARE @TSQL AS NVARCHAR(MAX)

--Prepare the query to delete the report files.

SET @TSQL = STUFF((SELECT

                      '; ' +

                      ' ;DELETE ' +

                      ' FROM ' +

                      ' [dbo].[DataSource] ' +

                      ' WHERE ' +

                      ' ItemID = ''' + CONVERT(VARCHAR(MAX), CL.ItemID) + ''''+

                      ' ;DELETE ' +

                      ' FROM ' +

                      ' [dbo].[Catalog] ' +

                      ' WHERE ' +

                      ' ItemID = ''' + CONVERT(VARCHAR(MAX), CL.ItemID) + ''''

                    FROM

                      [dbo].[Catalog] CL

                    WHERE

                      CL.[Type] = 2 --Report

                      AND '/' + CL.[Path] + '/' LIKE COALESCE('%/%' + @FilterReportPath + '%/%', '/' + CL.[Path] + '/')

                      AND CL.Name LIKE COALESCE('%' + @FilterReportName + '%', CL.Name)

                    FOR XML PATH('')), 1,1,'')

 --SELECT @TSQL

 --Execute the Dynamic Query

 EXEC SP_EXECUTESQL @TSQL


 

Comments

  1. Thank you for your valuable feedback

    ReplyDelete
  2. Really good information to show through this blog. I really appreciate you for all the valuable information that you are providing us through your blog.

    ReplyDelete
  3. I appreciate the time you spent finding that information

    ReplyDelete

Post a Comment

Hi User,
Thanks for visiting My Blog and please provide your valuable feedback and subscribe for more updates. Please don't post any spam content or comments.
Thank You

Popular Posts

Failed to execute the package or element. Build errors were encountered

Restore of database 'DataBase_Name' failed. (Microsoft.SqlServer.Management.RelationalEngineTasks)

Cannot convert "Column" between a unicode and a non-unicode string data types in SSIS