当前位置: 代码迷 >> Sql Server >> 请各位大神帮忙看看触发器的有关问题
  详细解决方案

请各位大神帮忙看看触发器的有关问题

热度:95   发布时间:2016-04-27 13:12:15.0
请各位大神帮忙看看触发器的问题
SQL code
CREATE TRIGGER [TR_UPDATACPTK001] ON ACPTKFOR UPDATE,INSERTAS    DECLARE       @TD001 CHAR(04),    @TD002 CHAR(11),    @TD003 CHAR(04),    @TD005 VARCHAR(60),    @TD006 VARCHAR(60),    @TD008 NUMERIC(16,6),    @TD010 NUMERIC(17,8),    @TK017 CHAR(4),    @TK018 CHAR(11)            BEGIN TRANSACTION    SET NOCOUNT ON    SELECT @TK017=TK017,@TK018=TK018 FROM INSERTED    SELECT @TD001=TD001,@TD002=TD002,@TD003=TD003,@TD005=TD005,@TD006=TD006,@TD008=TD008,@TD010=TD010        FROM PURTD WHERE [email protected] AND [email protected]    UPDATE ACPTK SET [email protected],[email protected],[email protected],[email protected]        WHERE @TD003='0001' AND [email protected] AND [email protected]    UPDATE ACPTK SET [email protected],[email protected],[email protected],[email protected]       WHERE @TD003='0002' AND [email protected] AND [email protected]    SET NOCOUNT OFFCOMMIT TRANSACTION
如果原表两行记录,只会更序号为0002的记录,而我想要是0001和0002都会更新上去?不知道哪里错了请各位大神帮忙看看

------解决方案--------------------
不要用变量,使用inserted和要更新的表直接关联
  相关解决方案