如何在插入触发器(如更新触发器)上检查列值 [英] How to check column value on insert trigger like Update trigger

查看:85
本文介绍了如何在插入触发器(如更新触发器)上检查列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个更新触发器,用于更新状态列值更改和更新其他表记录,并且工作正常.这是我的代码

I have a update trigger for update status column value change and update other table record and it is working fine. Here is my code

CREATE TRIGGER [dbo].[trgAfterUpdate] ON [dbo].[recharge_request]

FOR UPDATE
    AS

    DECLARE @status varchar(50);

    SELECT @status=i.status FROM inserted i; 

    IF UPDATE (status)
        BEGIN
            IF @status='Failure'
                --My Update Statement
            ELSE IF @status='Success'
                --My Update Statement
        END

现在,我还要创建一个插入触发器,以检查状态列的值并执行其他表操作.因为在某些情况下,状态列值不会更新为,如果列值为' Success '或' Fail ',我需要对插入执行一些操作.状态列的可能值为"成功","失败","待处理"和"处理".任何帮助将不胜感激.预先感谢!

Now I'm want to create an insert trigger also for check status column value and perform other table operation. because in some case status column value will not been update to I need to perform some operation on insert if column value is 'Success' or 'Fail'. status column possible values are 'Success', 'Fail', 'Pending' and 'Process'. any help will be appreciated. Thanks in advance!

推荐答案

我的问题已解决,这里是解决方法:

My Issue has been resolved here is solution:

CREATE TRIGGER [dbo].[trgAfterInsert] ON [dbo].[recharge_request]
AFTER INSERT
    AS
        BEGIN
            DECLARE @status varchar(50);

            SELECT @status=i.status FROM inserted i; 

            IF @status='Success'
                BEGIN
                    --My Update statement
                END
        END

这篇关于如何在插入触发器(如更新触发器)上检查列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆