'sql report server search is too broad

this is my first data analyst job and have not encountered a problem like this before. still at the beginner level.

first step i need to complete is to change all reports that contain SSN to instead show last 4 digits. Unfortunately BI is also responsible for making the changes as well as doing an audit of finding all reports that contain SSN information. using this report server search to help locate reports that contain SSN although it will bring up a all results that use SSN in any query - not necessarily displays SSN. looking over the report server search query to see if i can find a way to pull in info about how the text "SSN" is used in the report.

here is the prewritten script we use to do a report server search where i need to add more to find the answer. if more information is needed pls let me know!

USE ReportServer
--START - Keyword search in report definitions
    declare @keyword varchar(max) = 'ssn'; --*****input the search word*****
    declare @keyword_nospaces varchar(max) = REPLACE(@keyword,char(32),'');
--
--search for keyword within SSRS definition
IF OBJECT_ID('tempdb.dbo.#CTE_Catalog', 'U') IS NOT NULL
DROP TABLE #CTE_Catalog;
SELECT
        [ItemID]
        ,[Path]
        ,CASE   WHEN [Path] like '%/InDev%' then 'dev'
                WHEN [Path] like '%/ARCHIVE/%' then 'archive'   --added 8/17
                WHEN [Path] like '%/CU Reports%' then 'custom'
                WHEN [Path] like '%/Symitar Reports%' then 'stock'
                WHEN [Path] like '/Data Sources%' then 'datasource'
            END as Path_Grp
        ,[Name]
        ,[ParentID]
        ,[Type] --1 folder, 2 report, 5 datasource, 8 dataset, 9 report parts (e.g. Tablix name with filter/sort details)
        , CASE [Type]
            WHEN 1 then 'Folder'
            WHEN 2 then 'Report'
            WHEN 5 then 'DataSource'
            WHEN 8 then 'DataSet'
            WHEN 9 then 'Report Part'
            END TypeDesc
        ,CONVERT(varchar(max), CONVERT(varbinary(max), content)) AS xml_definition
        ,CONVERT(varbinary(max), content) AS xml_def
        ,[Intermediate]
        ,[SnapshotDataID]
        ,[LinkSourceID]
        ,[Property]
        ,[Description]
        ,[Hidden]
        ,[CreatedByID]
        ,[CreationDate]
        ,[ModifiedByID]
        ,[ModifiedDate]
        ,[MimeType]
        ,[SnapshotLimit]
        ,[Parameter]
        ,[PolicyID]
        ,[PolicyRoot]
        ,[ExecutionFlag]
        ,[ExecutionTime]
        ,[SubType]
        ,[ComponentID]
into #CTE_Catalog   --temp table to help with performance
    FROM [ReportServer].[dbo].[Catalog]

IF OBJECT_ID('tempdb..#keywordresults') IS NOT NULL
DROP TABLE #keywordresults;
SELECT  Path_Grp
        , rs_catalog.[path]
        , rpt.ItemName as deployed_Report_Name
        , [name]
        , TypeDesc
        , ModifiedDate
        , users.UserName 
        , CAST(xml_def AS xml) AS xmlTextString
into #keywordresults
FROM    #CTE_Catalog rs_catalog
left join   ReportServer.dbo.[Users] users  --left join in case stock reports don't have the user listed in our db?
    on  rs_catalog.ModifiedByID = users.UserID
left join   [SymitarSolutions].[security].[Items] rpt   --shows the actual Reporting Portal names
    on  rs_catalog.[Path] = rpt.[Path] collate database_default

WHERE   CHARINDEX( @keyword, xml_definition, 1) > 0-- searches for a string with or without spaces

select * from #keywordresults
--
--END - Keyword search in report definitions
--

--
--START - Review of Modifications
--
DECLARE @pastdays_num int = 7;  --default is to review changes in past 7 days
SELECT  Path_Grp
        , TypeDesc
        , rs_catalog.[path]
        , [name]
        , rpt.ItemName  as deployed_Report_Name
        , ModifiedDate
        , user_mod.UserName 
        , CreationDate
        , user_create.UserName
FROM    #CTE_Catalog rs_catalog
left join   ReportServer.dbo.[Users] user_mod   --left join in case stock reports don't have the user listed in our db?
    on  rs_catalog.ModifiedByID = user_mod.UserID
left join   ReportServer.dbo.[Users] user_create    --left join in case stock reports don't have the user listed in our db?
    on  rs_catalog.CreatedByID = user_create.UserID --8/17/17 corrected from ModifiedByID
left join   [SymitarSolutions].[security].[Items] rpt   --shows the actual Reporting Portal names
    on  rs_catalog.[Path] = rpt.[Path] collate database_default

WHERE ( ModifiedDate >= dateadd(dd,-@pastdays_num,getdate())
        OR  (   user_create.Username in ('PMARCU\ARCUAdmin','PMCU\sysadmin')    --check for changes to the stock report definitions
                and user_mod.Username NOT in ('PMARCU\ARCUAdmin','PMCU\sysadmin')
                and user_mod.Username <> user_create.UserName
            )
        )
and     TypeDesc not in ('Folder')  --folders appear to show changes whenever a report is added to it

ORDER BY ModifiedDate desc
--
--END - Review of Modifications



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source