May 15, 2012

sp_MSgetpeerconflictrow (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_MSgetpeerconflictrow(nvarchar @originator_id
, nvarchar @origin_datasource
, nvarchar @tran_id
, nvarchar @row_id
, nvarchar @conflict_table)

MetaData:

 create procedure sys.sp_MSgetpeerconflictrow   
(
@originator_id nvarchar(32) = '%' -- int
,@origin_datasource nvarchar(32) = '%' -- int
,@tran_id nvarchar(32) = '%' -- varbinary(16)
,@row_id nvarchar(32) = '%' -- timestamp
,@conflict_table nvarchar(270) -- [owner].[tabname]
)
as
begin
set nocount on
declare @retcode int = 0
,@cmd nvarchar(4000)
,@whcmd nvarchar(4000) = N'where c.__$is_winner = 0 '

select @cmd = N'select w.__$winner_origin_datasource_srvname, w.__$winner_origin_datasource_db, ''__$origin_datasource_srvname'' = h.originator_node, ''__$origin_datasource_db'' = h.originator_db, c.* from '
+ ISNULL(NULLIF(QUOTENAME(PARSENAME(@conflict_table, 2)) + N'.', N'.'), N'') + QUOTENAME(PARSENAME(@conflict_table, 1))
+ N' c join MSpeer_originatorid_history h on c.__$origin_datasource = h.originator_id'
+ N' left join (select distinct ''__$winner_origin_datasource_srvname'' = hw.originator_node, ''__$winner_origin_datasource_db'' = hw.originator_db, cw.__$change_id, cw.__$row_id from '
+ ISNULL(NULLIF(QUOTENAME(PARSENAME(@conflict_table, 2)) + N'.', N'.'), N'') + QUOTENAME(PARSENAME(@conflict_table, 1))
+ N' cw join MSpeer_originatorid_history hw on cw.__$origin_datasource = hw.originator_id where cw.__$is_winner = 1) as w on '
+ N' ((w.__$change_id is not null and w.__$change_id = c.__$row_id) or (w.__$change_id is null and w.__$row_id = c.__$change_id)) '

--
-- Security Check.
--
exec @retcode = sys.sp_MSreplcheck_publish
if @@ERROR <> 0 or @retcode <> 0
return(1)
--
-- passed the security check
--

if (@originator_id != N'%')
begin
select @whcmd = @whcmd + N' and __$originator_id = ' + quotename(@originator_id, '''')
end
if (@origin_datasource != N'%')
begin
select @whcmd = @whcmd + N' and __$origin_datasource = ' + quotename(@origin_datasource, '''')
end
if (@tran_id != N'%')
begin
select @whcmd = @whcmd + N' and __$tranid = ' + quotename(@tran_id, '''')
end
if (@row_id != N'%')
begin
select @whcmd = @whcmd + N' and __$row_id = ' + @row_id
end
select @cmd = @cmd + @whcmd

--
-- execute the generated select
--
execute (@cmd)
--
-- all done
--
end

No comments:

Post a Comment

Total Pageviews