Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSCheck_premature_expired_subscriptions

  No additional text.


Syntax
create procedure sys.sp_MSCheck_premature_expired_subscriptions
(
	@cutoffdate datetime,
	@premature_expired bit = 0 output
)
as
begin
    declare @min_sentgen bigint
    declare @max_delgen bigint

    select top 1 @min_sentgen = isnull(sentgen,0) from dbo.sysmergesubscriptions
    where status = 1
    and cleanedup_unsent_changes = 0
    order by sentgen

    if @min_sentgen is null
        return 0

    if exists (select * from #oldgens where gen > @min_sentgen)
    begin

        select top 1 @max_delgen = gen from #oldgens
        order by gen desc

        -- If this is not a leaf level subscriber, or alt sync partners are being used, make all the generations being cleaned up
        -- look like local generations in the temp table #oldgens
		if exists (select * from dbo.sysmergepublications where publisher_db = db_name() and UPPER(publisher) = UPPER (publishingservername()))
		or exists (select * from dbo.sysmergepublications where allow_synctoalternate = 1)
		begin
			update #oldgens set genstatus = 1
		end

	create table #expiringsubs (pubid uniqueidentifier NOT NULL, subid uniqueidentifier NOT NULL, last_sync_date datetime NULL)
	
	--This query is based on the following update statement. The purpose of this query is to determine if we are find any generations to clean up
	--but the same subscriber has been sync'ed within retention period, hence not supposed to be cleaned up and expired at this time.
	insert into #expiringsubs ( pubid, subid, last_sync_date)
	select sms1.pubid, sms1.subid, sms1.last_sync_date
	from dbo.sysmergesubscriptions sms1 join
	(
	            select sms.subid
	            from #oldgens og join dbo.MSmerge_generation_partition_mappings gpm
	            on og.gen = gpm.generation
	            and og.gen > @min_sentgen
	            and og.genstatus <> 2
	            join dbo.sysmergesubscriptions sms
	            on sms.partition_id = gpm.partition_id
	            and sms.sentgen < og.gen
	            join dbo.sysmergearticles sma on og.artnick = sma.nickname
	            where sma.pubid = sms.pubid
	
	            union all
	
	            select sms.subid
	            from #oldgens og
	            join dbo.sysmergesubscriptions sms
	            on og.gen > @min_sentgen
	            and og.genstatus <> 2
	            and isnull(sms.partition_id,0) = 0
	            and sms.sentgen < og.gen
	            join dbo.sysmergearticles sma on og.artnick = sma.nickname
	            where sma.pubid = sms.pubid
	
	
	            union all
	
	            select sms.subid
	            from #oldgens og join dbo.MSmerge_generation_partition_mappings gpm
	            on og.gen = gpm.generation
	            and og.gen > @min_sentgen
	            and og.genstatus <> 2
	            and gpm.partition_id = -1
	            join dbo.sysmergesubscriptions sms
	            on sms.sentgen < og.gen
	            join dbo.sysmergearticles sma on og.artnick = sma.nickname
	            where sma.pubid = sms.pubid
	
	            union all
	
	            select sms.subid
	            from #oldgens og join dbo.MSmerge_generation_partition_mappings gpm
	            on og.gen = gpm.generation
	            and og.gen > @min_sentgen
	            and og.genstatus <> 2
	            join dbo.sysmergesubscriptions sms
	            on sms.sentgen < og.gen
	            and sms.partition_id = -1
	            join dbo.sysmergearticles sma on og.artnick = sma.nickname
	            where sma.pubid = sms.pubid
	) as sms2
	on sms1.subid = sms2.subid
	
	if exists(select * from #expiringsubs where last_sync_date > @cutoffdate)
	begin
        	select @premature_expired = 1
        end
	
	--on the subscriber, the subid we mark for expiration is for the row for publisher, which will have a NULL last_sync_date
	--we will need to look for the subscriber row to compare the last_sync_date
	if exists(select * from dbo.sysmergesubscriptions sms
		join #expiringsubs es
		on sms.pubid = es.pubid
		where sms.db_name = db_name() collate database_default
			and sms.last_sync_date > @cutoffdate
			and es.last_sync_date is null	
		)			
	begin
		select @premature_expired = 1		
	end
	
	drop table #expiringsubs

    end

    return 0
end

 
Last revision
See also

  sp_mergemetadataretentioncleanup (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