Monday 10 November 2014

Execute SSRS Report Subscriptions Manually using SQL Query

-->Please change DateTime of LastRunTime field from below Query
-->select LastRunTime from [dbo].[Subscriptions] order by LastRunTime


-->in below Query update LastRunTime 
-->LastRunTime between '2014-11-09 07:00:04.607' and '2014-11-09 09:35:08.460'

select * into #TempR from
(select ROW_NUMBER()Over(order by j.name)ID,  cast(j.name as varchar(40)) Step 
from msdb.dbo.sysjobs j  
join  msdb.dbo.sysjobsteps js on js.job_id = j.job_id 
join ReportSchedule A on js.command like '%' + cast(A.subscriptionid as varchar(40)) + '%'


-->This join return the report id from LastRunTime date
left join
(select ItemID from [dbo].[Catalog]
where ItemID in (
select Report_OID from [dbo].[Subscriptions]
where LastRunTime between '2014-11-09 07:00:04.607' and '2014-11-09 09:35:08.460'
))P
on A.ReportID=P.ItemID
where ItemID is not null)P

declare @min int,@max int
set @min=(select Min(ID) from #TempR)
set @max=(select Max(ID) from #TempR)

select * from #TempR

--drop table #TempR

while(@min<=@max)
begin

declare @var nvarchar(max)
set @var=(select Step from #TempR where ID=@min)
execute msdb.dbo.sp_start_job @var
print @var

set @min=@min+1

end


No comments:

Post a Comment