May 2, 2012

sp_MSadd_merge_subscription (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_MSadd_merge_subscription(nvarchar @publisher
, nvarchar @publisher_db
, nvarchar @publication
, nvarchar @subscriber
, nvarchar @subscriber_db
, tinyint @subscription_type
, tinyint @sync_type
, tinyint @status
, int @frequency_type
, int @frequency_interval
, int @frequency_relative_interval
, int @frequency_recurrence_factor
, int @frequency_subday
, int @frequency_subday_interval
, int @active_start_time_of_day
, int @active_end_time_of_day
, int @active_start_date
, int @active_end_date
, nvarchar @optional_command_line
, nvarchar @agent_name
, bit @offloadagent
, nvarchar @offloadserver
, nvarchar @hostname
, nvarchar @description
, uniqueidentifier @subid
, nvarchar @internal
, int @publisher_engine_edition)

MetaData:

 CREATE PROCEDURE sys.sp_MSadd_merge_subscription  
(
@publisher sysname,
@publisher_db sysname,
@publication sysname,
@subscriber sysname,
@subscriber_db sysname,
@subscription_type tinyint = 0, -- 0 = push, 1 = pull
@sync_type tinyint = 1, -- 0 = none 1 = automatic snaphot 2 = no intial snapshot
@status tinyint = 1, -- 0 = inactive, 1 = subscribed, 2 = active
@frequency_type int = NULL,
@frequency_interval int = NULL,
@frequency_relative_interval int = NULL,
@frequency_recurrence_factor int = NULL,
@frequency_subday int = NULL,
@frequency_subday_interval int = NULL,
@active_start_time_of_day int = NULL,
@active_end_time_of_day int = NULL,
@active_start_date int = NULL,
@active_end_date int = NULL,
@optional_command_line nvarchar(4000) = NULL,
-- Job name, used in scripting.
@agent_name sysname = NULL,
@merge_jobid binary(16) = NULL OUTPUT,
-- Agent offload
@offloadagent bit = 0,
@offloadserver sysname = NULL,
@hostname sysname = NULL,
-- friendly name for merge
@description nvarchar(255) = NULL,
@subid uniqueidentifier = NULL,
-- used for jobstep level proxy accounts
@internal sysname = N'PRE-YUKON', -- Can be: 'PRE-YUKON', 'YUKON ADD SUB', 'YUKON ADD AGENT'
@publisher_engine_edition int = null
)
as
begin
set nocount on

declare @publisher_id smallint
declare @publication_id int
declare @retcode int

-- default values
declare @flushfrequency int
declare @frequencytype int
declare @frequencyinterval int
declare @frequencyrelativeinterval int
declare @frequencyrecurrencefactor int
declare @frequencysubday int
declare @frequencysubdayinterval int
declare @activestarttimeofday int
declare @activeendtimeofday int
declare @activestartdate int
declare @activeenddate int
declare @push int
declare @local_job bit
declare @thirdparty_flag bit
declare @subscribersecuritymode smallint
declare @subscriberlogin sysname
declare @subscriberpassword nvarchar(524)

select @push = 0

--
-- security check
-- Has to be executed from distribution database
--
if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
begin
raiserror(21482, 16, -1, 'sp_MSadd_merge_subscription', 'distribution')
return (1)
end
-- Check if publisher is a defined as a distribution publisher in the current database
exec @retcode = sys.sp_MSvalidate_distpublisher @publisher, @publisher_id OUTPUT
if @retcode <> 0
begin
return(1)
end

IF @offloadagent IS NOT NULL
AND @offloadagent != 0
BEGIN
-- "Parameter '@offloadagent' is no longer supported."
RAISERROR(21698, 16, -1, '@offloadagent')
RETURN 1
END

IF ISNULL(@offloadserver, N'') != N''
BEGIN
-- "Parameter '@offloadserver' is no longer supported."
RAISERROR(21698, 16, -1, '@offloadserver')
RETURN 1
END

-- Get the publication information
select @publication_id = publication_id,
@thirdparty_flag = thirdparty_flag from
dbo.MSpublications where
publisher_id = @publisher_id and
publisher_db = @publisher_db and
publication = @publication
if @publication_id is NULL
begin
raiserror (20026, 11, -1, @publication)
return (1)
end

-- Perform PAL check with retrieved @publication_id
exec @retcode = sys.sp_MScheck_pull_access
@agent_type = 1, -- merge agent
@publication_id = @publication_id
if @@error <> 0 or @retcode <> 0
begin
RAISERROR (15247, 11, -1)
return (1)
end

-- Make sure subscription does not already exist
if exists (select * from dbo.MSmerge_subscriptions where
publisher_id = @publisher_id and
publisher_db = @publisher_db and
publication_id = @publication_id and
UPPER(subscriber) = UPPER(@subscriber) and
subscriber_db = @subscriber_db)
begin
if @thirdparty_flag = 1
begin
raiserror (14058, 16, -1)
return(1)
end
else
begin
exec @retcode = sys.sp_MSdrop_merge_subscription
@publisher = @publisher,
@publisher_db = @publisher_db,
@publication = @publication,
@subscriber = @subscriber,
@subscriber_db = @subscriber_db,
@subscription_type = @subscription_type
if @retcode <> 0 or @@error <> 0
begin
return (1)
end
end
end

select @frequencytype = frequency_type,
@frequencyinterval = frequency_interval,
@frequencyrelativeinterval = frequency_relative_interval,
@frequencyrecurrencefactor = frequency_recurrence_factor,
@frequencysubday = frequency_subday,
@frequencysubdayinterval = frequency_subday_interval,
@activestarttimeofday = active_start_time_of_day,
@activeendtimeofday = active_end_time_of_day,
@activestartdate = active_start_date,
@activeenddate = active_end_date
from MSsubscriber_schedule
where UPPER(publisher) = UPPER(@publisher) and UPPER(subscriber) = UPPER(@subscriber) and agent_type = 1

if @frequency_type is null
select @frequency_type = @frequencytype

if @frequency_interval is null
select @frequency_interval = @frequencyinterval

if @frequency_relative_interval is null
select @frequency_relative_interval = @frequencyrelativeinterval

if @frequency_recurrence_factor is null
select @frequency_recurrence_factor = @frequencyrecurrencefactor

if @frequency_subday is null
select @frequency_subday = @frequencysubday

if @frequency_subday_interval is null
select @frequency_subday_interval = @frequencysubdayinterval

if @active_start_time_of_day is null
select @active_start_time_of_day = @activestarttimeofday

if @active_end_time_of_day is null
select @active_end_time_of_day = @activeendtimeofday

if @active_start_date is null
select @active_start_date = @activestartdate

if @active_end_date is null
select @active_end_date = @activeenddate

begin transaction

-- If push and agent name is not passed in, create local job.
if @subscription_type = @push
select @local_job = 1
else
select @local_job = 0

-- If a subid is not passed in, set it to NEWID() --
if (@subid IS NULL)
set @subid = newid()

insert into dbo.MSmerge_subscriptions (publisher_id, publisher_db, publication_id,
subscriber_id, subscriber_db, subscription_type, sync_type, status,
subscription_time, description, publisher, subscriber, subid)
values (@publisher_id, @publisher_db, @publication_id,
NULL, @subscriber_db, @subscription_type, @sync_type, @status,
getdate(),
@description,
@publisher,
@subscriber,
@subid)
if @@error <> 0
begin
goto FAILURE
end

-- Create Merge Agent
exec @retcode = sys.sp_MSadd_merge_agent
@name = @agent_name,
@publisher = @publisher,
@publisher_db = @publisher_db,
@publication = @publication,
@subscriber = @subscriber,
@subscriber_db = @subscriber_db,
@local_job = @local_job,
@frequency_type = @frequency_type,
@frequency_interval = @frequency_interval,
@frequency_relative_interval = @frequency_relative_interval,
@frequency_recurrence_factor = @frequency_recurrence_factor,
@frequency_subday = @frequency_subday,
@frequency_subday_interval = @frequency_subday_interval,
@active_start_time_of_day = @active_start_time_of_day,
@active_end_time_of_day = @active_end_time_of_day,
@active_start_date = @active_start_date,
@active_end_date = @active_end_date,
@optional_command_line = @optional_command_line,
@merge_jobid = @merge_jobid OUTPUT,
@subscription_type = @subscription_type,
@hostname = @hostname,
@internal = @internal,
@publisher_engine_edition = @publisher_engine_edition
if @retcode <> 0 or @@error <> 0
begin
goto FAILURE
end

commit transaction
return (0)

FAILURE:
-- UNDONE : This code is specific to 6.X nested transaction semantics --
if @@TRANCOUNT = 1
ROLLBACK TRANSACTION
else
COMMIT TRANSACTION
RETURN (1)
end

sp_MSadd_replcmds_mcit (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_MSadd_replcmds_mcit(int @publisher_database_id
, smallint @publisher_id
, nvarchar @publisher_db
, varbinary @data
, varbinary @1data
, varbinary @2data
, varbinary @3data
, varbinary @4data
, varbinary @5data
, varbinary @6data
, varbinary @7data
, varbinary @8data
, varbinary @9data
, varbinary @10data
, varbinary @11data
, varbinary @12data
, varbinary @13data
, varbinary @14data
, varbinary @15data
, varbinary @16data
, varbinary @17data
, varbinary @18data
, varbinary @19data
, varbinary @20data
, varbinary @21data
, varbinary @22data
, varbinary @23data
, varbinary @24data
, varbinary @25data
, varbinary @26data)

MetaData:

 CREATE PROCEDURE sys.sp_MSadd_replcmds_mcit  
@publisher_database_id int,
@publisher_id smallint,
@publisher_db sysname,
@data varbinary( 1595 ),
@1data varbinary(1595) = NULL,
@2data varbinary(1595) = NULL,
@3data varbinary(1595) = NULL,
@4data varbinary(1595) = NULL,
@5data varbinary(1595) = NULL,
@6data varbinary(1595) = NULL,
@7data varbinary(1595) = NULL,
@8data varbinary(1595) = NULL,
@9data varbinary(1595) = NULL,
@10data varbinary(1595) = NULL,
@11data varbinary(1595) = NULL,
@12data varbinary(1595) = NULL,
@13data varbinary(1595) = NULL,
@14data varbinary(1595) = NULL,
@15data varbinary(1595) = NULL,
@16data varbinary(1595) = NULL,
@17data varbinary(1595) = NULL,
@18data varbinary(1595) = NULL,
@19data varbinary(1595) = NULL,
@20data varbinary(1595) = NULL,
@21data varbinary(1595) = NULL,
@22data varbinary(1595) = NULL,
@23data varbinary(1595) = NULL,
@24data varbinary(1595) = NULL,
@25data varbinary(1595) = NULL,
@26data varbinary(1595) = NULL
AS

SET NOCOUNT ON

DECLARE @maxOffset binary(4)
,@maxSeqNo varbinary(16)
,@date datetime
,@x int
,@tempdata varbinary(1595)
,@prevdata varbinary(1595)

DECLARE @xactId varbinary(16),
@xactSeqNo varbinary(16),
@artId int,
@cmdId int,
@cmdType int,
@fIncomplete bit,
@cmdLen int,
@originator_id int,
@origSrvLen int,
@origDbLen int,
@hashKey int,
-- @origPublId int,
-- @origDbVersion int,
-- @origLSN varbinary(10),
@cmdText varbinary(1595),
@originator sysname,
@originatorDb sysname,
@originalXactSeqNo varbinary(10)

--
-- security check
-- only db_owner can execute this
--
if (is_member ('db_owner') != 1)
begin
raiserror(14260, 16, -1)
return (1)
end

select @date = GETDATE(),
@maxOffset = 0,
@xactSeqNo = substring( @data, 11, 10 ),
@cmdId = substring( @data, 25, 4)

select @originalXactSeqNo = @xactSeqNo

-- Look for the first insert into MS_repl_transactions
select @maxSeqNo = max(xact_seqno)
from MSrepl_transactions
where publisher_database_id = @publisher_database_id

-- Check if it is the same transaction
if @xactSeqNo = substring( @maxSeqNo, 1, 10 )
begin
IF @cmdId = 1
select @maxOffset = substring(@maxSeqNo, 11, 4) + 1
else
select @maxOffset = substring(@maxSeqNo, 11, 4)

if (@maxOffset > 0)
select @xactSeqNo = @xactSeqNo + @maxOffset
end

if @maxOffset is NULL
select @maxOffset = 0

select @maxOffset = @maxOffset + 1

select @x = 0
select @tempdata = @data
while @x <= 26
begin
select @prevdata = @tempdata
select @tempdata = CASE @x
when 0 then @data
when 1 then @1data
when 2 then @2data
when 3 then @3data
when 4 then @4data
when 5 then @5data
when 6 then @6data
when 7 then @7data
when 8 then @8data
when 9 then @9data
when 10 then @10data
when 11 then @11data
when 12 then @12data
when 13 then @13data
when 14 then @14data
when 15 then @15data
when 16 then @16data
when 17 then @17data
when 18 then @18data
when 19 then @19data
when 20 then @20data
when 21 then @21data
when 22 then @22data
when 23 then @23data
when 24 then @24data
when 25 then @25data
when 26 then @26data
end

IF @tempdata is null
goto END_CMDS

-- We will now breakup the binary data. Check HP_FIXED_DATA
-- in publish.cpp for all of the offsets listed below...
select @xactId = substring( @tempdata, 1, 10),
-- @xactSeqNo = see directly below for the setting of this value : usually = substring( @tempdata, 11, 10),
@artId = substring( @tempdata, 21, 4),
@cmdId = substring( @tempdata, 25, 4),
@cmdType = substring( @tempdata, 29, 4),
@fIncomplete = convert(bit, substring( @tempdata, 33, 1)),
@cmdLen = substring( @tempdata, 34, 2),
@origSrvLen = substring( @tempdata, 36, 2),
@origDbLen = substring( @tempdata, 38, 2),
@hashKey = substring( @tempdata, 40, 2),
-- @origPublId = Not used since MaxCMDsInTran is not supported in PeerToPeer. Usually would be : substring( @tempdata, 42, 4),
-- @origDbVersion = Not used since MaxCMDsInTran is not supported in PeerToPeer. Usually would be : substring( @tempdata, 46, 4),
-- @origLSN = Not used since MaxCMDsInTran is not supported in PeerToPeer. Usually would be : substring( @tempdata, 50, 10),
@cmdText = substring( @tempdata, 60, @cmdLen)
-- @originator = only done below if an originator len is detected : usually = substring( @tempdata, 60 + @cmdLen, @origSrvLen)
-- @originatorDb= only done below if an originator len is detected : usually = substring( @tempdata, 60 + @cmdLen + @origSrvLen, @origDbLen)

if @x != 0
begin
if(substring( @tempdata, 11, 10 ) = substring( @prevdata, 11, 10 )) -- same tran
begin
IF @cmdId = 1
begin
select @xactSeqNo = substring( @tempdata, 11, 10 ) + @maxOffset
select @maxOffset = @maxOffset + 1
end
end
else
select @xactSeqNo = substring( @tempdata, 11, 10 )
end

-- first command in tran
IF @cmdId = 1
begin
INSERT INTO MSrepl_transactions
VALUES (@publisher_database_id, @xactId, @xactSeqNo, @date)
end

-- Now insert into MSrepl_commands
if( @cmdType in( 37,38 ) )
begin
select @cmdType = 38 - @cmdType
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artId, @cmdType, @xactSeqNo
select @cmdType = (38 - @cmdType) | 0x80000000
end
-- Check all posted cmds of SQLCMD type to see if they are tracer records
-- sql cmd type is (47 | 0x40000000 ) or 1073741871
else if @cmdType = 1073741871
begin
declare @tracer_id int,
@retcode int

select @tracer_id = cast(cast(@cmdText as nvarchar) as int)

exec @retcode = sys.sp_MSupdate_tracer_history @tracer_id = @tracer_id
if @retcode <> 0 or @@error <> 0
return 1
end

-- only add it if the command is not empty
if @cmdLen > 0
begin
-- handle nonsync subscription setup when command type is
-- REPL_NOSYNC_SUBSCRIPTION_SETUP_LOG_CMD (54)
if ((@cmdType & 0xFFFFFFF) = 54)
begin
-- When logreader gets a log record with this type,
-- the MSnosyncsubsetup table should already exist,
-- report the failure if it does not exist.
if (object_id(N'dbo.MSnosyncsubsetup', 'U')) is NULL
begin
goto Failure
end
else
begin
declare @nosyncCommandStr nvarchar(max),
@publisher sysname,
@publication sysname,
@article sysname,
@subscriber sysname,
@destination_db sysname,
@subscriptionlsn binary(10),
@lsnsource tinyint,
@originator_publication_id int,
@originator_db_version int,
@originator_meta_data nvarchar(max),
@nosync_setup_script nvarchar(max),
@next_valid_lsn binary(10),
@next_valid_lsn_from_log binary(10)

select @originator_publication_id = CAST(CAST(substring(@cmdText, 1, 4) AS nvarchar) AS int),
@next_valid_lsn_from_log = CAST(substring(@cmdText, 5, 10) AS binary(10))
if @@error <> 0 goto Failure

-- Verify that the number of parameters is correct before using
-- these parameters in sp_MSsetupnosyncsubwithlsnatdist
if ((select count(*) from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log) <> 13) goto Failure
if @@error <> 0 goto Failure

select @publisher = cast((select parameterValue
from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log
and parameterName = N'publisher') as sysname),
@publisher_db = cast((select parameterValue
from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log
and parameterName = N'publisher_db') as sysname),
@publication = cast((select parameterValue
from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log
and parameterName = N'publication') as sysname),
@article = cast((select parameterValue
from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log
and parameterName = N'article') as sysname),
@subscriber = cast((select parameterValue
from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log
and parameterName = N'subscriber') as sysname),
@destination_db = cast((select parameterValue
from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log
and parameterName = N'destination_db') as sysname),
@subscriptionlsn = cast((select parameterValue
from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log
and parameterName = N'subscriptionlsn') as binary(10)),
@lsnsource = cast((select parameterValue
from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log
and parameterName = N'lsnsource') as tinyint),
@originator_publication_id = cast((select parameterValue
from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log
and parameterName = N'originator_publication_id') as int),
@originator_db_version = cast((select parameterValue
from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log
and parameterName = N'originator_db_version') as int),
@originator_meta_data = (select parameterValue
from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log
and parameterName = N'originator_meta_data'),
@nosync_setup_script = (select parameterValue
from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log
and parameterName = N'nosync_setup_script'),
@next_valid_lsn = cast((select parameterValue
from dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log
and parameterName = N'next_valid_lsn') as binary(10))
if @@error <> 0 goto Failure

select @nosyncCommandStr = N'exec sp_MSsetupnosyncsubwithlsnatdist
@publisher = @publisher,
@publisher_db = @publisher_db,
@publication = @publication,
@article = @article,
@subscriber = @subscriber,
@destination_db = @destination_db,
@subscriptionlsn = @subscriptionlsn,
@lsnsource = @lsnsource,
@originator_publication_id = @originator_publication_id,
@originator_db_version = @originator_db_version,
@originator_meta_data = @originator_meta_data,
@nosync_setup_script = @nosync_setup_script,
@next_valid_lsn = @next_valid_lsn'


exec sp_executesql
@stmt = @nosyncCommandStr,
@params = N'@publisher sysname,
@publisher_db sysname,
@publication sysname,
@article sysname,
@subscriber sysname,
@destination_db sysname,
@subscriptionlsn binary(10),
@lsnsource tinyint,
@originator_publication_id int,
@originator_db_version int,
@originator_meta_data nvarchar(max),
@nosync_setup_script nvarchar(max),
@next_valid_lsn binary(10)'
,
@publisher = @publisher,
@publisher_db = @publisher_db,
@publication = @publication,
@article = @article,
@subscriber = @subscriber,
@destination_db = @destination_db,
@subscriptionlsn = @subscriptionlsn,
@lsnsource = @lsnsource,
@originator_publication_id = @originator_publication_id,
@originator_db_version = @originator_db_version,
@originator_meta_data = @originator_meta_data,
@nosync_setup_script = @nosync_setup_script,
@next_valid_lsn = @next_valid_lsn

if @@error <> 0 goto Failure

end -- end of if (object_id(N'dbo.MSnosyncsubsetup, 'U')) is NOT NULL

-- Upon success of the execution of sp_MSsetupnosyncsubwithlsnatdist,
-- clean up the MSnosyncsubsetup table by deleting the parameters
-- regarding this specified nonsync subscription
delete dbo.MSnosyncsubsetup
where publisher_database_id = @publisher_database_id
and publication_id = @originator_publication_id
and artid = @artId
and next_valid_lsn = @next_valid_lsn_from_log

if @@error <> 0 goto Failure

goto Continue_next_command
Failure:
return 1
Continue_next_command:
end
else -- i.e., when (@cmdType & 0xFFFFFFF) is NOT 54
begin
-- Get the originator_id for the first command
if @origSrvLen <> 0 and @origDbLen <> 0
begin
select @originator_id = null,
@originator = substring( @tempdata, 60 + @cmdLen, @origSrvLen),
@originatorDb = substring( @tempdata, 60 + @cmdLen + @origSrvLen, @origDbLen)

select @originator_id = id
from MSrepl_originators
where publisher_database_id = @publisher_database_id
and UPPER(srvname) = UPPER(@originator)
and dbname = @originatorDb
and publication_id is NULL -- @origPublId
and dbversion is NULL -- @origDbVersion

if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname, publication_id, dbversion)
values (@publisher_database_id, UPPER(@originator), @originatorDb, NULL, NULL)

select @originator_id = @@identity
end
end
else
select @originator_id = 0

INSERT INTO MSrepl_commands
(
publisher_database_id,
xact_seqno,
type,
article_id,
originator_id,
command_id,
partial_command,
hashkey,
originator_lsn,
command
)
VALUES
(
@publisher_database_id,
@xactSeqNo,
@cmdType,
@artId,
@originator_id,
@cmdId,
@fIncomplete,
@hashKey,
NULL, -- @origLSN
@cmdText
)
end -- end of i.e., when (@cmdType & 0xFFFFFFF) in (54, 55, 56)
end -- end of if @cmdLen > 0

select @x = @x + 1

end

END_CMDS:
IF @@ERROR <> 0
return (1)

sp_MSadd_replmergealert (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_MSadd_replmergealert(int @agent_type
, int @agent_id
, int @error_id
, int @alert_error_code
, nvarchar @publisher
, nvarchar @publisher_db
, nvarchar @publication
, int @publication_type
, nvarchar @subscriber
, nvarchar @subscriber_db
, nvarchar @article
, nvarchar @destination_object
, nvarchar @source_object
, ntext @alert_error_text)

MetaData:

 CREATE PROCEDURE sys.sp_MSadd_replmergealert   
(
@agent_type int,
@agent_id int,
@error_id int,
@alert_error_code int,
@publisher sysname,
@publisher_db sysname,
@publication sysname,
@publication_type int,
@subscriber sysname,
@subscriber_db sysname,
@article sysname,
@destination_object sysname,
@source_object sysname,
@alert_error_text ntext
)
AS
begin
declare @retcode int

SET NOCOUNT ON

exec @retcode = sys.sp_MScheck_pull_access
@agent_id = @agent_id,
@agent_type = 1 -- merge agent
if @@error <> 0 or @retcode <> 0
return (1)

INSERT INTO msdb.dbo.sysreplicationalerts (status, agent_type , agent_id, error_id, alert_error_code, time, publisher,
publisher_db, publication, publication_type, subscriber, subscriber_db,
article, destination_object, source_object, alert_error_text)
VALUES (0, @agent_type, @agent_id, @error_id, @alert_error_code, getdate(), @publisher,
@publisher_db, @publication, @publication_type, @subscriber, @subscriber_db,
@article, @destination_object, @source_object, @alert_error_text)

IF @@ERROR <> 0
BEGIN
RETURN (1)
END

return (0)
end

sp_MSadd_repl_commands27hp (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_MSadd_repl_commands27hp(smallint @publisher_id
, nvarchar @publisher_db
, varbinary @data
, varbinary @1data
, varbinary @2data
, varbinary @3data
, varbinary @4data
, varbinary @5data
, varbinary @6data
, varbinary @7data
, varbinary @8data
, varbinary @9data
, varbinary @10data
, varbinary @11data
, varbinary @12data
, varbinary @13data
, varbinary @14data
, varbinary @15data
, varbinary @16data
, varbinary @17data
, varbinary @18data
, varbinary @19data
, varbinary @20data
, varbinary @21data
, varbinary @22data
, varbinary @23data
, varbinary @24data
, varbinary @25data
, varbinary @26data)

MetaData:

 CREATE PROCEDURE sys.sp_MSadd_repl_commands27hp  
(
@publisher_id smallint,
@publisher_db sysname,
@data varbinary( 1575 ),
@1data varbinary(1575) = NULL,
@2data varbinary(1575) = NULL,
@3data varbinary(1575) = NULL,
@4data varbinary(1575) = NULL,
@5data varbinary(1575) = NULL,
@6data varbinary(1575) = NULL,
@7data varbinary(1575) = NULL,
@8data varbinary(1575) = NULL,
@9data varbinary(1575) = NULL,
@10data varbinary(1575) = NULL,
@11data varbinary(1575) = NULL,
@12data varbinary(1575) = NULL,
@13data varbinary(1575) = NULL,
@14data varbinary(1575) = NULL,
@15data varbinary(1575) = NULL,
@16data varbinary(1575) = NULL,
@17data varbinary(1575) = NULL,
@18data varbinary(1575) = NULL,
@19data varbinary(1575) = NULL,
@20data varbinary(1575) = NULL,
@21data varbinary(1575) = NULL,
@22data varbinary(1575) = NULL,
@23data varbinary(1575) = NULL,
@24data varbinary(1575) = NULL,
@25data varbinary(1575) = NULL,
@26data varbinary(1575) = NULL
)
AS
begin
SET NOCOUNT ON

DECLARE @xact_id varbinary(10)
DECLARE @xact_seqno varbinary(10)
DECLARE @artid int
DECLARE @command_id int
DECLARE @cmd_type int
DECLARE @partial_command bit
DECLARE @command varbinary(1024)

DECLARE @max_offset binary(4)
DECLARE @seqno varbinary(16)
DECLARE @1seqno varbinary(16)
DECLARE @2seqno varbinary(16)
DECLARE @3seqno varbinary(16)
DECLARE @4seqno varbinary(16)
DECLARE @5seqno varbinary(16)
DECLARE @6seqno varbinary(16)
DECLARE @7seqno varbinary(16)
DECLARE @8seqno varbinary(16)
DECLARE @9seqno varbinary(16)
DECLARE @10seqno varbinary(16)
DECLARE @11seqno varbinary(16)
DECLARE @12seqno varbinary(16)
DECLARE @13seqno varbinary(16)
DECLARE @14seqno varbinary(16)
DECLARE @15seqno varbinary(16)
DECLARE @16seqno varbinary(16)
DECLARE @17seqno varbinary(16)
DECLARE @18seqno varbinary(16)
DECLARE @19seqno varbinary(16)
DECLARE @20seqno varbinary(16)
DECLARE @21seqno varbinary(16)
DECLARE @22seqno varbinary(16)
DECLARE @23seqno varbinary(16)
DECLARE @24seqno varbinary(16)
DECLARE @25seqno varbinary(16)
DECLARE @26seqno varbinary(16)
DECLARE @max_seqno varbinary(16)

DECLARE @originator sysname
DECLARE @originator_db sysname

DECLARE @publisher_database_id int
DECLARE @date datetime
declare @originator_id int

DECLARE @cmd_data_len smallint
DECLARE @orig_srv_len smallint
DECLARE @orig_db_len smallint
DECLARE @MaxCmdsInTranOn int

--
-- security check
-- only db_owner can execute this
--
if (is_member ('db_owner') != 1)
begin
raiserror(14260, 16, -1)
return (1)
end

SELECT @date = GETDATE()
SELECT @MaxCmdsInTranOn = 0
-- Get publisher database id.
SELECT @publisher_database_id = id from MSpublisher_databases where publisher_id = @publisher_id and
publisher_db = @publisher_db

SELECT @MaxCmdsInTranOn = category & 0x40 from master.dbo.sysdatabases where dbid = db_id()

select @max_offset = 0
-- First insert into MS_repl_transactions
if(@MaxCmdsInTranOn > 0 )
begin
select @max_seqno = max(xact_seqno) from MSrepl_transactions
where publisher_database_id = @publisher_database_id
if substring( @data, 11, 10 ) = substring( @max_seqno, 1, 10 ) -- same tran
begin
IF convert( int, substring( @data, 25, 4 ) ) = 1
select @max_offset = substring(@max_seqno, 11, 4) + 1 -- increment offset
else
select @max_offset = substring(@max_seqno, 11, 4) -- keep the same offset
if (@max_offset > 0)
select @seqno = substring( @data, 11, 10 ) + @max_offset
else
select @seqno = substring( @data, 11, 10 )
end
else
select @seqno = substring( @data, 11, 10 )
end
else
select @seqno = substring( @data, 11, 10 )
IF convert( int, substring( @data, 25, 4 ) ) = 1 -- first command in tran
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @data, 1, 10 ), @seqno, @date)

if @max_offset is NULL
select @max_offset = 0
select @max_offset = @max_offset + 1

IF @1data is null
goto INSERT_CMDS

if(substring( @1data, 11, 10 ) = substring( @data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @1data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @1seqno = substring( @1data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @1data, 1, 10 ), @1seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @1seqno = @seqno
end
else
begin
select @1seqno = substring( @1data, 11, 10 )
IF convert( int, substring( @1data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @1data, 1, 10 ), @1seqno, @date)
end

IF @2data is null
goto INSERT_CMDS

if(substring( @2data, 11, 10 ) = substring( @1data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @2data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @2seqno = substring( @2data, 11, 10 )+ @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @2data, 1, 10 ), @2seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @2seqno = @1seqno
end
else
begin
select @2seqno = substring( @2data, 11, 10 )
IF convert( int, substring( @2data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @2data, 1, 10 ), @2seqno, @date)
end

IF @3data is null
goto INSERT_CMDS

if(substring( @3data, 11, 10 ) = substring( @2data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @3data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @3seqno = substring( @3data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @3data, 1, 10 ), @3seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @3seqno = @2seqno
end
else
begin
select @3seqno = substring( @3data, 11, 10 )
IF convert( int, substring( @3data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @3data, 1, 10 ), @3seqno, @date)
end

IF @4data is null
goto INSERT_CMDS

if(substring( @4data, 11, 10 ) = substring( @3data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @4data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @4seqno = substring( @4data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @4data, 1, 10 ), @4seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @4seqno = @3seqno
end
else
begin
select @4seqno = substring( @4data, 11, 10 )
IF convert( int, substring( @4data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @4data, 1, 10 ), @4seqno, @date)
end

IF @5data is null
goto INSERT_CMDS
if(substring( @5data, 11, 10 ) = substring( @4data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @5data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @5seqno = substring( @5data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @5data, 1, 10 ), @5seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @5seqno = @4seqno
end
else
begin
select @5seqno = substring( @5data, 11, 10 )
IF convert( int, substring( @5data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @5data, 1, 10 ), @5seqno, @date)
end

IF @6data is null
goto INSERT_CMDS
if(substring( @6data, 11, 10 ) = substring( @5data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @6data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @6seqno = substring( @6data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @6data, 1, 10 ), @6seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @6seqno = @5seqno
end
else
begin
select @6seqno = substring( @6data, 11, 10 )
IF convert( int, substring( @6data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @6data, 1, 10 ), @6seqno, @date)
end

IF @7data is null
goto INSERT_CMDS
if(substring( @7data, 11, 10 ) = substring( @6data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @7data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @7seqno = substring( @7data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @7data, 1, 10 ), @7seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @7seqno = @6seqno
end
else
begin
select @7seqno = substring( @7data, 11, 10 )
IF convert( int, substring( @7data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @7data, 1, 10 ), @7seqno, @date)
end

IF @8data is null
goto INSERT_CMDS
if(substring( @8data, 11, 10 ) = substring( @7data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @8data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @8seqno = substring( @8data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @8data, 1, 10 ), @8seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @8seqno = @7seqno
end
else
begin
select @8seqno = substring( @8data, 11, 10 )
IF convert( int, substring( @8data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @8data, 1, 10 ), @8seqno, @date)
end

IF @9data is null
goto INSERT_CMDS
if(substring( @9data, 11, 10 ) = substring( @8data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @9data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @9seqno = substring( @9data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @9data, 1, 10 ), @9seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @9seqno = @8seqno
end
else
begin
select @9seqno = substring( @9data, 11, 10 )
IF convert( int, substring( @9data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @9data, 1, 10 ), @9seqno, @date)
end

IF @10data is null
goto INSERT_CMDS
if(substring( @10data, 11, 10 ) = substring( @9data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @10data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @10seqno = substring( @10data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @10data, 1, 10 ), @10seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @10seqno = @9seqno
end
else
begin
select @10seqno = substring( @10data, 11, 10 )
IF convert( int, substring( @10data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @10data, 1, 10 ), @10seqno, @date)
end

IF @11data is null
goto INSERT_CMDS
if(substring( @11data, 11, 10 ) = substring( @10data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @11data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @11seqno = substring( @11data, 11, 10 )+ @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @11data, 1, 10 ), @11seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @11seqno = @10seqno
end
else
begin
select @11seqno = substring( @11data, 11, 10 )
IF convert( int, substring( @11data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @11data, 1, 10 ), @11seqno, @date)
end

IF @12data is null
goto INSERT_CMDS
if(substring( @12data, 11, 10 ) = substring( @11data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @12data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @12seqno = substring( @12data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @12data, 1, 10 ), @12seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @12seqno = @11seqno
end
else
begin
select @12seqno = substring( @12data, 11, 10 )
IF convert( int, substring( @12data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @12data, 1, 10 ), @12seqno, @date)
end

IF @13data is null
goto INSERT_CMDS
if(substring( @13data, 11, 10 ) = substring( @12data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @13data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @13seqno = substring( @13data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @13data, 1, 10 ), @13seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @13seqno = @12seqno
end
else
begin
select @13seqno = substring( @13data, 11, 10 )
IF convert( int, substring( @13data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @13data, 1, 10 ), @13seqno, @date)
end

IF @14data is null
goto INSERT_CMDS
if(substring( @14data, 11, 10 ) = substring( @13data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @14data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @14seqno = substring( @14data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @14data, 1, 10 ), @14seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @14seqno = @13seqno
end
else
begin
select @14seqno = substring( @14data, 11, 10 )
IF convert( int, substring( @14data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @14data, 1, 10 ), @14seqno, @date)
end

IF @15data is null
goto INSERT_CMDS
if(substring( @15data, 11, 10 ) = substring( @14data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @15data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @15seqno = substring( @15data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @15data, 1, 10 ), @15seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @15seqno = @14seqno
end
else
begin
select @15seqno = substring( @15data, 11, 10 )
IF convert( int, substring( @15data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @15data, 1, 10 ), @15seqno, @date)
end

IF @16data is null
goto INSERT_CMDS
if(substring( @16data, 11, 10 ) = substring( @15data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @16data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @16seqno = substring( @16data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @16data, 1, 10 ), @16seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @16seqno = @15seqno
end
else
begin
select @16seqno = substring( @16data, 11, 10 )
IF convert( int, substring( @16data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @16data, 1, 10 ), @16seqno, @date)
end

IF @17data is null
goto INSERT_CMDS
if(substring( @17data, 11, 10 ) = substring( @16data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @17data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @17seqno = substring( @17data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @17data, 1, 10 ), @17seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @17seqno = @16seqno
end
else
begin
select @17seqno = substring( @17data, 11, 10 )
IF convert( int, substring( @17data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @17data, 1, 10 ), @17seqno, @date)
end

IF @18data is null
goto INSERT_CMDS
if(substring( @18data, 11, 10 ) = substring( @17data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @18data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @18seqno = substring( @18data, 11, 10 )+ @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @18data, 1, 10 ), @18seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @18seqno = @17seqno
end
else
begin
select @18seqno = substring( @18data, 11, 10 )
IF convert( int, substring( @18data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @18data, 1, 10 ), @18seqno, @date)
end

IF @19data is null
goto INSERT_CMDS
if(substring( @19data, 11, 10 ) = substring( @18data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @19data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @19seqno = substring( @19data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @19data, 1, 10 ), @19seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @19seqno = @18seqno
end
else
begin
select @19seqno = substring( @19data, 11, 10 )
IF convert( int, substring( @19data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @19data, 1, 10 ), @19seqno, @date)
end

IF @20data is null
goto INSERT_CMDS
if(substring( @20data, 11, 10 ) = substring( @19data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @20data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @20seqno = substring( @20data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @20data, 1, 10 ), @20seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @20seqno = @19seqno
end
else
begin
select @20seqno = substring( @20data, 11, 10 )
IF convert( int, substring( @20data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @20data, 1, 10 ), @20seqno, @date)
end

IF @21data is null
goto INSERT_CMDS
if(substring( @21data, 11, 10 ) = substring( @20data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @21data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @21seqno = substring( @21data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @21data, 1, 10 ), @21seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @21seqno = @20seqno
end
else
begin
select @21seqno = substring( @21data, 11, 10 )
IF convert( int, substring( @21data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @21data, 1, 10 ), @21seqno, @date)
end

IF @22data is null
goto INSERT_CMDS
if(substring( @22data, 11, 10 ) = substring( @21data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @22data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @22seqno = substring( @22data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @22data, 1, 10 ), @22seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @22seqno = @21seqno
end
else
begin
select @22seqno = substring( @22data, 11, 10 )
IF convert( int, substring( @22data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @22data, 1, 10 ), @22seqno, @date)
end

IF @23data is null
goto INSERT_CMDS
if(substring( @23data, 11, 10 ) = substring( @22data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @23data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @23seqno = substring( @23data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @23data, 1, 10 ), @23seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @23seqno = @22seqno
end
else
begin
select @23seqno = substring( @23data, 11, 10 )
IF convert( int, substring( @23data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @23data, 1, 10 ), @23seqno, @date)
end

IF @24data is null
goto INSERT_CMDS
if(substring( @24data, 11, 10 ) = substring( @23data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @24data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @24seqno = substring( @24data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @24data, 1, 10 ), @24seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @24seqno = @23seqno
end
else
begin
select @24seqno = substring( @24data, 11, 10 )
IF convert( int, substring( @24data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @24data, 1, 10 ), @24seqno, @date)
end

IF @25data is null
goto INSERT_CMDS
if(substring( @25data, 11, 10 ) = substring( @24data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @25data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @25seqno = substring( @25data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @25data, 1, 10 ), @25seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @25seqno = @24seqno
end
else
begin
select @25seqno = substring( @25data, 11, 10 )
IF convert( int, substring( @25data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @25data, 1, 10 ), @25seqno, @date)
end

IF @26data is null
goto INSERT_CMDS
if(substring( @26data, 11, 10 ) = substring( @25data, 11, 10 )) -- same tran
begin
IF convert( int, substring( @26data, 25, 4 ) ) = 1 -- only happens with -MaxCmdsInTran
begin
select @26seqno = substring( @26data, 11, 10 ) + @max_offset
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @26data, 1, 10 ), @26seqno, @date)
select @max_offset = @max_offset + 1
end
else
select @26seqno = @25seqno
end
else
begin
select @26seqno = substring( @26data, 11, 10 )
IF convert( int, substring( @26data, 25, 4 ) ) = 1
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
substring( @26data, 1, 10 ), @26seqno, @date)
end

INSERT_CMDS:

if datalength( @data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @data, 34, 2 )
select @orig_srv_len = substring( @data, 36, 2 )
select @orig_db_len = substring( @data, 38, 2 )

if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @data, 40 + @cmd_data_len, @orig_srv_len ), substring( @data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

select @cmd_type = substring(@data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@seqno,
@cmd_type,
substring(@data,21,4),
@originator_id,
substring(@data,25,4),
convert(bit,substring(@data,33,1)),
substring(@data,40,@cmd_data_len) )

end

IF @1data is null
return
IF datalength( @1data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @1data, 34, 2 )
select @orig_srv_len = substring( @1data, 36, 2 )
select @orig_db_len = substring( @1data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @1data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @1data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @1data, 40 + @cmd_data_len, @orig_srv_len ), substring( @1data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@1data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@1data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @1seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@1seqno,
@cmd_type,
substring(@1data,21,4),
@originator_id,
substring(@1data,25,4),
convert(bit,substring(@1data,33,1)),
substring(@1data,40,@cmd_data_len) )
end

IF @2data is null
return
IF datalength( @2data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @2data, 34, 2 )
select @orig_srv_len = substring( @2data, 36, 2 )
select @orig_db_len = substring( @2data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @2data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @2data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @2data, 40 + @cmd_data_len, @orig_srv_len ), substring( @2data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@2data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@2data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @2seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@2seqno,
@cmd_type,
substring(@2data,21 ,4),
@originator_id,
substring(@2data,25 ,4),
convert(bit,substring(@2data,33 ,1)),
substring(@2data,40,@cmd_data_len) )

end

IF @3data is null
return
IF datalength( @3data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @3data, 34, 2 )
select @orig_srv_len = substring( @3data, 36, 2 )
select @orig_db_len = substring( @3data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @3data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @3data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @3data, 40 + @cmd_data_len, @orig_srv_len ), substring( @3data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@3data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@3data,21,4)
select @cmd_type = 38 - @cmd_type
select @xact_seqno = substring( @3data, 11, 10 )
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @3seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@3seqno,
@cmd_type,
substring(@3data,21 ,4),
@originator_id,
substring(@3data,25 ,4),
convert(bit,substring(@3data,33 ,1)),
substring(@3data,40,@cmd_data_len) )

end

IF @4data is null
return
IF datalength( @4data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @4data, 34, 2 )
select @orig_srv_len = substring( @4data, 36, 2 )
select @orig_db_len = substring( @4data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @4data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @4data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @4data, 40 + @cmd_data_len, @orig_srv_len ), substring( @4data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@4data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@4data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @4seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@4seqno,
@cmd_type,
substring(@4data,21 ,4),
@originator_id,
substring(@4data,25 ,4),
convert(bit,substring(@4data,33 ,1)),
substring(@4data,40,@cmd_data_len) )

end

IF @5data is null
return
IF datalength( @5data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @5data, 34, 2 )
select @orig_srv_len = substring( @5data, 36, 2 )
select @orig_db_len = substring( @5data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @5data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @5data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @5data, 40 + @cmd_data_len, @orig_srv_len ), substring( @5data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@5data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@5data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @5seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@5seqno,
@cmd_type,
substring(@5data,21 ,4),
@originator_id,
substring(@5data,25 ,4),
convert(bit,substring(@5data,33 ,1)),
substring(@5data,40,@cmd_data_len) )

end

IF @6data is null
return
IF datalength( @6data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @6data, 34, 2 )
select @orig_srv_len = substring( @6data, 36, 2 )
select @orig_db_len = substring( @6data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @6data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @6data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @6data, 40 + @cmd_data_len, @orig_srv_len ), substring( @6data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@6data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@6data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @6seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@6seqno,
@cmd_type,
substring(@6data,21 ,4),
@originator_id,
substring(@6data,25 ,4),
convert(bit,substring(@6data,33 ,1)),
substring(@6data,40,@cmd_data_len) )

end

IF @7data is null
return
IF datalength( @7data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @7data, 34, 2 )
select @orig_srv_len = substring( @7data, 36, 2 )
select @orig_db_len = substring( @7data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @7data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @7data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @7data, 40 + @cmd_data_len, @orig_srv_len ), substring( @7data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@7data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@7data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @7seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@7seqno,
@cmd_type,
substring(@7data,21 ,4),
@originator_id,
substring(@7data,25 ,4),
convert(bit,substring(@7data,33 ,1)),
substring(@7data,40,@cmd_data_len) )

end

IF @8data is null
return
IF datalength( @8data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @8data, 34, 2 )
select @orig_srv_len = substring( @8data, 36, 2 )
select @orig_db_len = substring( @8data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @8data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @8data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @8data, 40 + @cmd_data_len, @orig_srv_len ), substring( @8data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@8data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@8data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @8seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@8seqno,
@cmd_type,
substring(@8data,21 ,4),
@originator_id,
substring(@8data,25 ,4),
convert(bit,substring(@8data,33 ,1)),
substring(@8data,40,@cmd_data_len) )
end

IF @9data is null
return
IF datalength( @9data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @9data, 34, 2 )
select @orig_srv_len = substring( @9data, 36, 2 )
select @orig_db_len = substring( @9data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and upper(srvname) = upper(convert(sysname, substring( @9data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @9data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @9data, 40 + @cmd_data_len, @orig_srv_len ), substring( @9data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@9data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@9data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @9seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@9seqno,
@cmd_type,
substring(@9data,21 ,4),
@originator_id,
substring(@9data,25 ,4),
convert(bit,substring(@9data,33 ,1)),
substring(@9data,40,@cmd_data_len) )
end

IF @10data is null
return
IF datalength( @10data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @10data, 34, 2 )
select @orig_srv_len = substring( @10data, 36, 2 )
select @orig_db_len = substring( @10data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @10data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @10data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @10data, 40 + @cmd_data_len, @orig_srv_len ), substring( @10data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@10data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@10data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @10seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@10seqno,
@cmd_type,
substring(@10data,21 ,4),
@originator_id,
substring(@10data,25 ,4),
convert(bit,substring(@10data,33 ,1)),
substring(@10data,40,@cmd_data_len) )

end

IF @11data is null
return
IF datalength( @11data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @11data, 34, 2 )
select @orig_srv_len = substring( @11data, 36, 2 )
select @orig_db_len = substring( @11data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @11data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @11data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @11data, 40 + @cmd_data_len, @orig_srv_len ), substring( @11data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@11data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@11data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @11seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@11seqno,
@cmd_type,
substring(@11data,21 ,4),
@originator_id,
substring(@11data,25 ,4),
convert(bit,substring(@11data,33 ,1)),
substring(@11data,40,@cmd_data_len) )
end

IF @12data is null
return
IF datalength( @12data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @12data, 34, 2 )
select @orig_srv_len = substring( @12data, 36, 2 )
select @orig_db_len = substring( @12data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @12data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @12data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @12data, 40 + @cmd_data_len, @orig_srv_len ), substring( @12data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@12data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@12data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @12seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@12seqno,
@cmd_type,
substring(@12data,21 ,4),
@originator_id,
substring(@12data,25 ,4),
convert(bit,substring(@12data,33 ,1)),
substring(@12data,40,@cmd_data_len) )
end


IF @13data is null
return
IF datalength( @13data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @13data, 34, 2 )
select @orig_srv_len = substring( @13data, 36, 2 )
select @orig_db_len = substring( @13data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @13data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @13data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @13data, 40 + @cmd_data_len, @orig_srv_len ), substring( @13data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@13data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@13data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @13seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@13seqno,
@cmd_type,
substring(@13data,21 ,4),
@originator_id,
substring(@13data,25 ,4),
convert(bit,substring(@13data,33 ,1)),
substring(@13data,40,@cmd_data_len) )
end

IF @14data is null
return
IF datalength( @14data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @14data, 34, 2 )
select @orig_srv_len = substring( @14data, 36, 2 )
select @orig_db_len = substring( @14data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @14data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @14data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @14data, 40 + @cmd_data_len, @orig_srv_len ), substring( @14data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@14data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@14data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @14seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@14seqno,
@cmd_type,
substring(@14data,21 ,4),
@originator_id,
substring(@14data,25 ,4),
convert(bit,substring(@14data,33 ,1)),
substring(@14data,40,@cmd_data_len) )
end


IF @15data is null
return
IF datalength( @15data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @15data, 34, 2 )
select @orig_srv_len = substring( @15data, 36, 2 )
select @orig_db_len = substring( @15data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @15data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @15data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @15data, 40 + @cmd_data_len, @orig_srv_len ), substring( @15data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@15data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@15data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @15seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@15seqno,
@cmd_type,
substring(@15data,21 ,4),
@originator_id,
substring(@15data,25 ,4),
convert(bit,substring(@15data,33 ,1)),
substring(@15data,40,@cmd_data_len) )
end

IF @16data is null
return
IF datalength( @16data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @16data, 34, 2 )
select @orig_srv_len = substring( @16data, 36, 2 )
select @orig_db_len = substring( @16data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @16data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @16data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @16data, 40 + @cmd_data_len, @orig_srv_len ), substring( @16data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@16data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@16data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @16seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@16seqno,
@cmd_type,
substring(@16data,21 ,4),
@originator_id,
substring(@16data,25 ,4),
convert(bit,substring(@16data,33 ,1)),
substring(@16data,40,@cmd_data_len) )
end


IF @17data is null
return
IF datalength( @17data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @17data, 34, 2 )
select @orig_srv_len = substring( @17data, 36, 2 )
select @orig_db_len = substring( @17data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @17data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @17data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @17data, 40 + @cmd_data_len, @orig_srv_len ), substring( @17data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@17data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@17data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @17seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@17seqno,
@cmd_type,
substring(@17data,21 ,4),
@originator_id,
substring(@17data,25 ,4),
convert(bit,substring(@17data,33 ,1)),
substring(@17data,40,@cmd_data_len) )
end


IF @18data is null
return
IF datalength( @18data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @18data, 34, 2 )
select @orig_srv_len = substring( @18data, 36, 2 )
select @orig_db_len = substring( @18data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @18data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @18data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @18data, 40 + @cmd_data_len, @orig_srv_len ), substring( @18data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@18data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@18data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @18seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@18seqno,
@cmd_type,
substring(@18data,21 ,4),
@originator_id,
substring(@18data,25 ,4),
convert(bit,substring(@18data,33 ,1)),
substring(@18data,40,@cmd_data_len) )
end


IF @19data is null
return
IF datalength( @19data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @19data, 34, 2 )
select @orig_srv_len = substring( @19data, 36, 2 )
select @orig_db_len = substring( @19data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @19data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @19data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @19data, 40 + @cmd_data_len, @orig_srv_len ), substring( @19data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@19data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@19data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @19seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@19seqno,
@cmd_type,
substring(@19data,21 ,4),
@originator_id,
substring(@19data,25 ,4),
convert(bit,substring(@19data,33 ,1)),
substring(@19data,40,@cmd_data_len) )
end


IF @20data is null
return
IF datalength( @20data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @20data, 34, 2 )
select @orig_srv_len = substring( @20data, 36, 2 )
select @orig_db_len = substring( @20data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @20data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @20data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @20data, 40 + @cmd_data_len, @orig_srv_len ), substring( @20data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@20data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@20data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @20seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@20seqno,
@cmd_type,
substring(@20data,21 ,4),
@originator_id,
substring(@20data,25 ,4),
convert(bit,substring(@20data,33 ,1)),
substring(@20data,40,@cmd_data_len) )
end

IF @21data is null
return
IF datalength( @21data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @21data, 34, 2 )
select @orig_srv_len = substring( @21data, 36, 2 )
select @orig_db_len = substring( @21data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @21data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @21data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @21data, 40 + @cmd_data_len, @orig_srv_len ), substring( @21data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@21data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@21data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @21seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@21seqno,
@cmd_type,
substring(@21data,21 ,4),
@originator_id,
substring(@21data,25 ,4),
convert(bit,substring(@21data,33 ,1)),
substring(@21data,40,@cmd_data_len) )
end

IF @22data is null
return
IF datalength( @22data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @22data, 34, 2 )
select @orig_srv_len = substring( @22data, 36, 2 )
select @orig_db_len = substring( @22data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @22data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @22data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @22data, 40 + @cmd_data_len, @orig_srv_len ), substring( @22data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@22data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@22data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @22seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@22seqno,
@cmd_type,
substring(@22data,21 ,4),
@originator_id,
substring(@22data,25 ,4),
convert(bit,substring(@22data,33 ,1)),
substring(@22data,40,@cmd_data_len) )
end

IF @23data is null
return
IF datalength( @23data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @23data, 34, 2 )
select @orig_srv_len = substring( @23data, 36, 2 )
select @orig_db_len = substring( @23data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @23data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @23data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @23data, 40 + @cmd_data_len, @orig_srv_len ), substring( @23data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@23data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@23data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @23seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@23seqno,
@cmd_type,
substring(@23data,21 ,4),
@originator_id,
substring(@23data,25 ,4),
convert(bit,substring(@23data,33 ,1)),
substring(@23data,40,@cmd_data_len) )
end

IF @24data is null
return
IF datalength( @24data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @24data, 34, 2 )
select @orig_srv_len = substring( @24data, 36, 2 )
select @orig_db_len = substring( @24data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @24data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @24data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @24data, 40 + @cmd_data_len, @orig_srv_len ), substring( @24data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@24data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@24data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @24seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@24seqno,
@cmd_type,
substring(@24data,21 ,4),
@originator_id,
substring(@24data,25 ,4),
convert(bit,substring(@24data,33 ,1)),
substring(@24data,40,@cmd_data_len) )
end


IF @25data is null
return
IF datalength( @25data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @25data, 34, 2 )
select @orig_srv_len = substring( @25data, 36, 2 )
select @orig_db_len = substring( @25data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @25data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @25data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @25data, 40 + @cmd_data_len, @orig_srv_len ), substring( @25data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@25data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@25data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @25seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@25seqno,
@cmd_type,
substring(@25data,21 ,4),
@originator_id,
substring(@25data,25 ,4),
convert(bit,substring(@25data,33 ,1)),
substring(@25data,40,@cmd_data_len) )
end


IF @26data is null
return
IF datalength( @26data ) > 39
begin
-- Get the originator_id for the first command
select @cmd_data_len = substring( @26data, 34, 2 )
select @orig_srv_len = substring( @26data, 36, 2 )
select @orig_db_len = substring( @26data, 38, 2 )
if @orig_srv_len <> 0 and @orig_db_len <> 0
begin
set @originator_id = null
select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id
and UPPER(srvname) = upper(convert(sysname, substring( @26data, 40 + @cmd_data_len, @orig_srv_len )))
and dbname = substring( @26data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len )
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, substring( @26data, 40 + @cmd_data_len, @orig_srv_len ), substring( @26data, 40 + @cmd_data_len + @orig_srv_len, @orig_db_len ))
select @originator_id = @@identity
end
end
else
select @originator_id = 0

-- Now insert into MSrepl_commands
select @cmd_type = substring(@26data,29,4)
if( @cmd_type in( 37,38 ) )
begin
select @artid = substring(@26data,21,4)
select @cmd_type = 38 - @cmd_type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @artid, @cmd_type, @26seqno
select @cmd_type = (38 - @cmd_type) | 0x80000000
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id,
@26seqno,
@cmd_type,
substring(@26data,21 ,4),
@originator_id,
substring(@26data,25 ,4),
convert(bit,substring(@26data,33 ,1)),
substring(@26data,40,@cmd_data_len) )
end


IF @@ERROR <> 0
return (1)
end

Total Pageviews