Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSrepl_add_expired_sub_cleanup_job

  No additional text.


Syntax

CREATE PROCEDURE sys.sp_MSrepl_add_expired_sub_cleanup_job
(
	@publisher sysname = NULL
)
AS
BEGIN
	DECLARE @retcode       int,
			@agentname     sysname,
			@alert_name    sysname,
			@alert_id      int,
			@command	   nvarchar(max),
			@category_name sysname,
			@description   nvarchar(500)

	SET @retcode = 0
	
    -- Get expired subscription cleanup agent name
    set @agentname = formatmessage(20569) +
    				 CASE
    				 	WHEN @publisher IS NOT NULL THEN N' ' + QUOTENAME(UPPER(@publisher))
    				 	ELSE N''
    				 END

	-- Add expired subscription cleanup job if it doesn't already exist
    IF NOT EXISTS
    (
		SELECT	*
		FROM	msdb.dbo.sysjobs_view
		WHERE	name = @agentname COLLATE DATABASE_DEFAULT
		  AND	UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
		  AND	master_server = 0
	)
    BEGIN
        SELECT @command	= 'EXEC sys.sp_expired_subscription_cleanup' +
        				  CASE
        				  	WHEN @publisher IS NOT NULL THEN N' @publisher = N' + QUOTENAME(UPPER(@publisher), '''')
        				  	ELSE N''
        				  END

        SET @description = formatmessage(20542)

        SELECT	@category_name = name
        FROM	msdb.dbo.syscategories
        WHERE	category_id = 17

        EXEC @retcode = msdb.dbo.sp_MSadd_repl_job	@agentname,
													@subsystem              = 'TSQL',
													@server                 = @@servername,
													@databasename           = N'master',
													@description            = @description,
													@freqtype               = 4,				-- daily
													@activestarttimeofday   = 010000,			-- from 01:00:00 am
													@command                = @command,
													@enabled                = 1,
													@retryattempts          = 0,
													@loghistcompletionlevel = 0,
													@category_name          = @category_name

        IF (@@ERROR != 0 OR @retcode != 0)
        BEGIN
             RETURN (1)
        END
    END

    -- Add Expired subscription cleanup alert if it doesn't already exist
    SELECT	@category_name = name
    FROM	msdb.dbo.syscategories
    WHERE	category_id = 20

    SET	@alert_name = formatmessage(20538)

	-- corresponding to formatmessage(20538)
    SET	@alert_id = 14157

    IF NOT EXISTS
    (
    	SELECT	*
    	FROM	msdb.dbo.sysalerts
    	WHERE	message_id = @alert_id
    )
    BEGIN
        EXEC @retcode = msdb.dbo.sp_add_alert	@enabled = 0,
        										@name = @alert_name,
        										@category_name = @category_name,
        										@message_id = 14157

        IF (@@ERROR != 0 OR @retcode != 0)
        BEGIN
             RETURN (1)
        END
    END

	RETURN @retcode
END

 
Last revision 2008RTM
See also

  sp_adddistributor (Procedure)
sp_MSrepl_adddistpublisher (Procedure)
sp_replicationdboption (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash