Home Microsoft SQL Server DigiMailing iRN Contact


  No additional text.


create procedure sys.sp_MSinsertbeforeimageclause @pubid uniqueidentifier, @objid int, @tablenickstr nvarchar(12),
    @phase int as
    set nocount on
    declare @cmdpiece nvarchar(4000)
    declare @before_objid int
    declare @sync_objid int
    declare @before_name sysname
    declare @collist nvarchar(4000)
    declare @vallist nvarchar(4000)
    declare @colname sysname
    declare @colordinal smallint
    declare @argname sysname
    -- Security Checking
    -- sysadmin or db_owner or replication agent have access

    if {fn ISPALUSER(@pubid)} <> 1
        raiserror(14260, 16, -1)
        return (1)
    -- Do we have a before table?
    select @before_objid = max(before_image_objid) from  dbo.sysmergearticles where objid = @objid and
            before_image_objid is not null
    select @before_name = OBJECT_NAME(@before_objid)

    select @sync_objid = sync_objid from dbo.sysmergearticles where objid=@objid and pubid=@pubid

    if @before_name is null
            return 0

    set @collist = ''
    -- Loop over columns to make the column list for the insert / select command

    declare col_cursor CURSOR LOCAL FAST_FORWARD for select name from sys.columns
        where object_id = @before_objid and name <> 'generation' and name <> 'system_delete'
            and name in (select name from sys.columns where object_id = @sync_objid)
                order by column_id


    open col_cursor
    set @vallist = ''
    fetch next from col_cursor into @colname
    while (@@fetch_status <> -1)
            set @collist = @collist + QUOTENAME(@colname) + ', '
            exec sys.sp_MSgetcolordinalfromcolname @objid, @sync_objid, @colname, @colordinal out
            select @argname = '@p' + rtrim(convert(nchar, @colordinal))
            set @vallist = @vallist + @argname + ', '
            fetch next from col_cursor into @colname
    close col_cursor
    deallocate col_cursor

    -- Our list has all of the columns except generation since that gets set to a local variable
    -- Make the insert command
    set @cmdpiece = '
            declare @gen_cur bigint
            exec sys.sp_MSmerge_getgencur_public ' + @tablenickstr + ', 0, @gen_cur output
            if @retcode<>0 or @@error<>0
                return 4
    insert into #tempcmd (phase, cmdtext) values (@phase, @cmdpiece)
    --select @cmdpiece

    set @cmdpiece = '
            insert into ' + QUOTENAME(@before_name) + ' ( ' + @collist +
           ' generation, system_delete) values (' + @vallist + ' @gen_cur, 1 )'
    insert into #tempcmd (phase, cmdtext) values (@phase, @cmdpiece)
    --select @cmdpiece

    return 0

Last revision 2008RTM
See also

  sp_MSdrop_rlrecon (Procedure)
sp_MSmakeinsertproc (Procedure)


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