我试图设置一个循环来向多个经理发送相同的报告,并更改参数以适应他们的团队。
我已经订阅了一个订阅设置,我在第一次尝试之前和我使用过的代码已经循环(通过设置计划在1分钟内开火)后成功测试。
然而SP_Start_job
无法启动工作,只是返回1.每隔5次运行就会重新调整错误:
消息14262,级别16,状态1,过程sp_verify_job_identifiers,第41行 指定的@job_id(' 5274E5CB-9D5A-4998-96E4-B82017CA0588')不存在。
DECLARE @MID VARCHAR(max),
@MEmail VARCHAR(max),
@UpdatedSettings VARCHAR(max),
@SubscriptionID VARCHAR(36), @passed int
--Declares a cycle getting UID for manager and their EMAIL.
--Email will be used to update the job destination
SELECT @SubscriptionID = a.SubscriptionID
FROM ReportServer$TOFINOREPORTING.dbo.[Subscriptions] a
INNER JOIN ReportServer$TOFINOREPORTING.dbo.[Catalog] AS b ON a.[Report_OID] = b.[ItemID]
WHERE b.NAME = 'Automation OperativePerformence'
DECLARE ManagerCursor CURSOR STATIC
FOR
(
SELECT U.ID AS ManagerID,
u.Email AS Email
FROM [dbo].[Global.User] U
INNER JOIN [dbo].[Global.UserRole] UR ON UR.UserId = U.ID
INNER JOIN [dbo].[Global.Role] R ON R.ID = UR.RoleID
WHERE R.NAME = 'ReportingAutomation'
AND U.IsActive = 1
AND U.Title LIKE 'Repairs Field Manager%'
)
OPEN ManagerCursor
--UPDate cycle
FETCH NEXT
FROM managerCursor
INTO @MID,
@MEMail
SELECT @MID,
@MEmail
WHILE @@FETCH_STATUS = 0
BEGIN
--TEST EMAIL OVERRIDE
SET @MEmail = 'Stephen.Wallace@email.org.uk'
UPDATE dbo.BAT_SubscriptionController
SET MID = @MID,
MEmail = @MEmail
SELECT *
FROM BAT_SubscriptionController
SELECT @UpdatedSettings = LEFT(Cast(a.extensionSettings AS NVARCHAR(max)), (- 1 + CHARINDEX('<Name>TO</Name><Value>', Cast(a.extensionSettings AS NVARCHAR(max))) + LEN(cast('<Name>TO</Name><Value>' AS NVARCHAR(max)))
)) + @MEmail + RIGHT(Cast(a.extensionSettings AS NVARCHAR(max)), len(Cast(a.extensionSettings AS VARCHAR(max))) - Charindex(
'</Value></ParameterValue><ParameterValue><Name>IncludeReport</Name>', Cast(a.extensionSettings AS NVARCHAR(max))) + 1)
FROM ReportServer$TOFINOREPORTING.dbo.[Subscriptions] a
INNER JOIN ReportServer$TOFINOREPORTING.dbo.[Catalog] AS b ON a.[Report_OID] = b.[ItemID]
WHERE a.SubscriptionID = @SubscriptionID
SELECT @UpdatedSettings,
LEN(@UpdatedSettings),
@SubscriptionID
UPDATE ReportServer$TOFINOREPORTING.dbo.[Subscriptions]
SET extensionSettings = @UpdatedSettings
WHERE SubscriptionID = @SubscriptionID
EXEC @passed = msdb.dbo.sp_start_job @job_id = @SubscriptionID
Select @passed
WAITFOR DELAY '00:00:30'
FETCH NEXT
FROM managerCursor
INTO @MID,
@MEMail
END
CLOSE ManagerCursor
DEALLOCATE ManagerCursor
答案 0 :(得分:0)
明显的解决方案 - 我的错误
SP_Start_job需要Job_Name / id,而不是订阅名称ID。
将我的订阅ID阶段更改为使用
SELECT @SubscriptionID = a.SubscriptionID , @jobID= s.ScheduleID
FROM ReportServer$TOFINOREPORTING.dbo.[Subscriptions] a
INNER JOIN ReportServer$TOFINOREPORTING.dbo.[Catalog] AS b ON a.[Report_OID] = b.[ItemID]
INNER JOIN ReportServer$TOFINOREPORTING.dbo.ReportSchedule rs
ON rs.SubscriptionID = a.SubscriptionID
INNER JOIN ReportServer$TOFINOREPORTING.dbo.Schedule S
ON rs.ScheduleID = S.ScheduleID
WHERE b.NAME =
和exec来 St_Start_job @ Job_Name = @ jobID
解决问题。
谢谢你@Manoj的代码。我花了很多时间来看明显的。