Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSinsertbeforeimageclause

  No additional text.


Syntax

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
    begin
        raiserror(14260, 16, -1)
        return (1)
    end
    -- 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
        begin
            return 0
        end

    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

    FOR READ ONLY

    open col_cursor
    set @vallist = ''
    fetch next from col_cursor into @colname
    while (@@fetch_status <> -1)
        begin
            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
        end
    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)
       



News

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