I am trying to default a multi-select parameter in and SSRS report to be what the user selected the last time they ran a report. I query the ExecutionLogStorage table to get the row of the last run report for that user. The Parameters field contains this:&StartRow=1&EndRow=1000&LoginID=40&ProjectAssessment=16&ShowColumns=Asset&ShowColumns=Category&ShowColumns=IOL&ShowColumns=Vulnerability%20Exposed&AssetDescription=&ShowColumns is the multi-select parameter. My issue is how to build a string from that to return "Asset, Category, IOL, Vulnerability%20Exposed"This is what I've tried so far for ParameterValue: SELECT TOP 1 ParameterValue FROM ( SELECT TimeEnd = els.TimeEnd --, ParameterValue = IIF(CHARINDEX('&' + @ParameterName + '=', ParsString) = 0, null, -- SUBSTRING(ParsString -- , StartIndex -- , CHARINDEX('&', ParsString, StartIndex) - StartIndex)) --, ParameterValue = IIF(CHARINDEX('&' + @ParameterName + '=', ParsString) = 0, null, -- REPLACE(SUBSTRING(ParsString -- , StartIndex -- , LastIndex),('&' + @ParameterName + '='),', ')) , ParameterValue = IIF(CHARINDEX('&' + @ParameterName + '=', ParsString) = 0, null, SUBSTRING(ParsString , StartIndex , LastIndex)) FROM (SELECT ReportID , TimeEnd , ParsString = '&' + CONVERT(VARCHAR(MAX), Parameters) + '&' , StartIndex = CHARINDEX('&' + @ParameterName + '=', '&' + CONVERT(VARCHAR(MAX), Parameters) + '&') + LEN('&' + @ParameterName + '=') , LastIndex = LEN(CAST(Parameters as varchar(8000))) - CHARINDEX(@ParameterName, REVERSE(CAST(Parameters as varchar(8000)))) + 1 FROM [ReportServer$SQLEXPRESS].[dbo].[ExecutionLogStorage] WHERE CHARINDEX('&LoginID' + '=' + @LoginID, CONVERT(VARCHAR(MAX), Parameters)) > 0 ) AS els INNER JOIN [ReportServer$SQLEXPRESS].[dbo].[Catalog] AS c ON c.ItemID = els.ReportID WHERE c.Name = @ReportName UNION ALL SELECT TimeEnd = CAST('1900-01-01' AS DateTime) , ParameterValue = null ) i ORDER BY TimeEnd DESC
↧