create procedure sys.sp_MSget_pullsubsagent_owner (
@publisher sysname,
@publisher_db sysname,
@publication sysname, /* publication name */
@owner_sid varbinary(85) OUTPUT
) AS
declare @job_id uniqueidentifier
set nocount on
select @owner_sid = null
if object_id('MSreplication_subscriptions', 'U') is not NULL
begin
-- Get the job_id corresponding to the publication
select @job_id = agent_id
from MSreplication_subscriptions
where upper(@publisher) = upper(publisher) and
@publisher_db = publisher_db and
@publication = publication
-- Using the job_id in MSsubscription properties to get the owner_sid
-- in msdb.dbo.sysjobs
select @owner_sid = owner_sid
from msdb.dbo.sysjobs
where @job_id = job_id
end