开发者

Replication & Triggers

All SQL Servers are SQL Server 2008....

I have a tabl开发者_如何学运维e that is replicated to a data center. I have written an AFTER INSERT & AFTER UPDATE trigger on this table. When data is replicated to the table, the subscription reports errors

column name or number of supplied values does not match table definition

I can manually insert records & the trigger works fine though when replication attempts to insert records, I get the message above. Below are my triggers..

I am sure the error emanates from the trigger, but I am at a loss why...

AHIA,

LarryR...

-- =============================================
-- Description: Updates tblReceivingHeaderStatus_1 
-- =============================================

create TRIGGER [dbo].[UPD_tblReceivingHeaderStatus_1]
   ON [dbo].[tblReceivingHeader]
   AFTER UPDATE
AS 
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

declare @SeqNum numeric ,@Location numeric

select @SeqNum = i.SeqNum, @Location = i.Location
from tblReceivingHeaderStatus_1 D
left join inserted i on D.Location = i.Location and D.SeqNum = i.SeqNum

UPDATE tblReceivingHeaderStatus_1 
SET AdjTax = inserted.AdjTax,
    AdjDeliveryFee = inserted.AdjDeliveryFee,
    AdjDiscount = inserted.AdjDiscount,
    AdjInvoiceTotal = inserted.AdjInvoiceTotal,
    AdjItemCount= inserted.AdjItemCount,
    AdjInvoiceInfo = inserted.AdjInvoiceInfo,
    InvoiceAdjReason = ISNULL(inserted.InvoiceAdjReason,''),
    PaidFlag = inserted.PaidFlag,
    StartDate = inserted.StartDate,
    CheckComments = inserted.CheckComments,
    POeMailSent = 
      case inserted.CheckComments
         when '.' then 'P'
         else ''
      end,
    PONumber = inserted.PONumber,
    [Status] = inserted.[Status],
    MiscFlag2 = 'T'
FROM 
    inserted
WHERE 
    inserted.seqnum = tblReceivingHeaderStatus_1.seqnum AND 
    inserted.location = tblReceivingHeaderStatus_1.location ;

--this assigns all inventory PO receivers to someone in pricing to approve
update tblReceivingHeaderStatus_1  
set NextApprover = 1
from tblReceivingHeaderStatus_1
left join apvendp on vmvend = vendornum 
where 
  recdevice = 'P' and 
  status = '1' and 
  NextApprover <> 1 and 
  vminex = 'I' ;

--update tblReceivingHeader to show the record has been

--updated in tblReceivingHeaderStatus_1

update tblReceivingHeader
set MovedToAs400 = 'Y'
where tblReceivingHeader.SeqNum = @SeqNum
  and tblReceivingHeader.Location = @Location ;

END


-- ==========================================================
-- Description: Insert records into tblReceivingHeaderStatus_1 
-- ==========================================================
create TRIGGER [dbo].[INS_INTO_tblReceivingHeaderStatus_1]
   ON [dbo].[tblReceivingHeader]
   AFTER INSERT
AS 
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.

SET NOCOUNT ON;

declare @SeqNum numeric ,@Location numeric

--get the seqnum & location from the inserted record
select @SeqNum = i.SeqNum, @Location = i.Location
from tblReceivingHeaderStatus_1 D
left join inserted i on D.Location = i.Location and D.SeqNum = i.SeqNum;

INSERT INTO tblReceivingHeaderStatus_1
  select 
      SeqNum,VendorNum,InvoiceNum,InvoiceTotal,ItemCount,
      InvoiceDate,Status,Location,AdjTax,AdjDeliveryFee,AdjDiscount,
      AdjInvoiceTotal,AdjItemCount,isnull(AdjInvoiceInfo,''),Tax,
      DeliveryFee,Discount,ApprovedTime,ApprovedDate,ApprovedBy,
      InvoiceAdjReason,'N', GETDATE(),PaidFlag,StartDate,
      case CheckComments
         when '.' then 'P'
         else ''
      end,
      ' ', 0, PONumber, recDevice, '', '', '', 'T', '', '', '', '', 0, 0, 0, '', 
      msrepl_tran_version
FROM inserted;

-- update tblReceivingHeader to show the record has been
-- inserted into tblReceivingHeaderStatus_1
update tblReceivingHeader
set MovedToAs400 = 'Y'
where 
   tblReceivingHeader.SeqNum = @SeqNum
   and tblReceivingHeader.Location = @Location;
END


Your problem is here

INSERT INTO tblReceivingHeaderStatus_1

select ...

Don't do that. Instead specify the columns you're inserting into e.g.

INSERT INTO tblReceivingHeaderStatus_1
(  fieldA, 
   FieldB
   ...
)
SELECT ...


I bet you have an identity column on tblReceivingHeaderStatus_1 that's marked as not for replication...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜