我不确定这是否是最好的方法,但是对我有用。唯一的缺点是我需要添加随机延迟几秒才能使用当前参数。请在下面查看我的代码。
在SSRS的SQL JOB中,我修改了SQL JOB的步骤1。在执行exec addevent之前,我会更新参数值。
declare @xml as xml
set quoted_identifier ON
DECLARE db_cursor CURSOR FOR
SELECT C.[City]
FROM #FService C
GROUP BY C.[City]
ORDER BY C.[City]
DECLARE @CityLoop VARCHAR(50);
OPEN db_cursor;
FETCH NEXT FROM db_cursor INTO @CityLoop;
WHILE @@FETCH_STATUS = 0
BEGIN
-- THIS IS TO UPDATE XML
set @xml = (select Parameters
from ReportServer.dbo.Subscriptions sb
where sb.SubscriptionID = 'GUID')
set @xml.modify(' replace value of
(/ParameterValues/ParameterValue[2]/Value/text())[1] with
sql:variable("@CityLoop") ')
-- HERE WE UPDATE PARAMETER TABLE
update ReportServer.dbo.Subscriptions
set parameters = convert(nvarchar(max), @xml)
where SubscriptionID = 'GUID'
-- HERE IS THE ORIGINAL EXEC
exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='GUID'
WAITFOR DELAY '00:00:30';
--RAISERROR (@DealLoop, 0, 1) WITH NOWAIT
FETCH NEXT FROM db_cursor INTO @CityLoop;
END;
CLOSE db_cursor;
DEALLOCATE db_cursor;
[请注意,我们为SSRS添加了30秒的延迟,以提取并执行报告。有没有一种方法可以避免随机秒数并直接执行报告?或AddEvent是执行此操作的唯一方法?
如果没有延迟,该报告将仅使用最后一个@cityLoop参数运行。这就是为什么我添加延迟然后通过每30秒为参数查询中可用的每个城市发送电子邮件来正常工作的原因
我正在使用SSRS和SQL Server 2012
感谢您的帮助
为了解决冒险的随机等待时间,我进行了调整。SQL Server中心文章[https://www.sqlservercentral.com/articles/dynamically-name-reportfile-export-in-ssrs]
它基本上使用等待执行
-- WAIT for EXECUTION
set @bool1 = ISNULL((select eventdata from event where eventdata = @SBidEventData), '')
while @bool1 <> ''
begin
set @bool1 = ISNULL((select eventdata from event where eventdata = @SBidEventData), '')
if @bool1 = ''
begin
-- SET PATH AND PARAMETER TO THE WAY IT WAS
WAITFOR DELAY '000:00:07'
update Catalog
set Path = '/Report/Report1'
where ItemID = @ItemID
update Subscriptions
set Parameters = '<ParameterValues><ParameterValue><Name>Year</Name><Value>2019</Value></ParameterValue><ParameterValue><Name>Category</Name><Value>HONDA</Value></ParameterValue><ParameterValue><Name>Month</Name><Value>12</Value></ParameterValue></ParameterValues>'
where SubscriptionID = @SBidEventData
end
结束