SQL Server 2008 - 插入触发器不触发

时间:2016-01-25 21:09:19

标签: sql sql-server vb.net triggers

我有一个VB.NET应用程序,它根据用户选择创建一些INSERTUPDATEDELETE语句。我可以告诉SQL在SQL Server 2008上成功执行(我看到表记录正确调整),除了我的一个插入触发器没有触发。

应用程序代码生成的SQL:

insert into [RECLASS_BALANCE_ADJSTMNT]( PRGRM_REC_ID, DEDUCTN_REC_ID, RBA_YR_PD_NUM, RBA_AMOUNT, RBA_TYPE, ADJUSTER_USER_ID ) 
values (5504, 8154, dbo.getCurrentYrPdNum(), abs(-21510.70), 'M', '10139638');

insert into [MATCH] (DEDUCTN_REC_ID, PRGRM_REC_ID, YR_PD_NUM, MATCH_TYPE_FLG)
values (8154, 5504, dbo.getCurrentYrPdNum(), 'M');

delete from [POTENTIAL_MATCH] 
where deductn_rec_id = 8154 
  and prgrm_rec_id = 5504;

update [PROGRAM_GL_DTL] 
set MATCH_FLG = 'Y', MATCH_FLG_MODIFIED_TIMESTAMP = getdate() 
where PRGRM_REC_ID = 5504;

update [DEDUCTION] 
set MATCH_FLG = MATCH_FLG + 1
where DEDUCTN_REC_ID = 8154;

INSERT触发器:

CREATE TRIGGER [dbo].[check_partial_offset_status] 
ON [dbo].[RECLASS_BALANCE_ADJSTMNT] 
FOR INSERT
AS
BEGIN
    DECLARE @deductnRecId int;
    DECLARE @deductnBalance decimal(18,2);
    DECLARE @deductnOriginalAmount decimal(18,2);

    SELECT @deductnRecId = i.deductn_rec_id FROM inserted i; 

    SELECT @deductnBalance = ds.ytd_amt, @deductnOriginalAmount = ds.original_invoice_amount 
    FROM deduction_summary_updt ds 
    WHERE ds.deductn_rec_id = @deductnRecId;

    IF ABS(@deductnBalance) > 0
    BEGIN
        UPDATE deduction 
        SET comment_id = 12 
        WHERE deductn_rec_id = @deductnRecId;
    END  --partial matched

    IF @deductnBalance = @deductnOriginalAmount
    BEGIN
        UPDATE deduction 
        SET comment_id = 6 
        WHERE deductn_rec_id = @deductnRecId;
    END   --unmatched

    IF @deductnBalance = 0
    BEGIN
        UPDATE deduction 
        SET comment_id = 9 
        WHERE deductn_rec_id = @deductnRecId; 
    END   --fully matched

    DECLARE @prgrmRecId int;
    DECLARE @prgrmBalance decimal(18,2);
    DECLARE @prgrmOriginalAmount decimal(18,2);

    SELECT @prgrmRecId = i.prgrm_rec_id FROM inserted i;

    SELECT @prgrmBalance = rs.ytd_amt, @prgrmOriginalAmount = rs.reclass_amount 
    FROM reclass_summary rs 
    WHERE rs.prgrm_rec_id = @prgrmRecId;

    IF ABS(@prgrmBalance) > 0
    BEGIN
        UPDATE program_gl_dtl 
        SET comment_id = 12 
        WHERE prgrm_rec_id = @prgrmRecId;
    END    --partial matched

    IF @prgrmBalance = @prgrmOriginalAmount
    BEGIN
        UPDATE program_gl_dtl 
        SET comment_id = 5 
        WHERE prgrm_rec_id = @prgrmRecId;
    END    --unmatched

    IF @prgrmBalance = 0
    BEGIN
        UPDATE program_gl_dtl 
        SET comment_id = 10 
        WHERE prgrm_rec_id = @prgrmRecId; 
    END    --fully matched      
END
GO

我试图理解为什么应用程序代码生成的“INSERT INTO [RECLASS_BALANCE_ADJSTMNT] ..”不会导致触发器触发。

我感谢任何帮助。谢谢!

0 个答案:

没有答案