日期:2014-05-18  浏览次数:20454 次

请各位大神帮忙看看触发器的问题
SQL code
CREATE TRIGGER [TR_UPDATACPTK001] ON ACPTK
FOR UPDATE,INSERT
AS
    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 TD001=@TK017 AND TD002=@TK018
    UPDATE ACPTK SET UDF02=@TD005,UDF03=@TD006,UDF52=@TD010,UDF53=@TD008 
       WHERE @TD003='0001' AND TK017=@TD001 AND TK018=@TD002
    UPDATE ACPTK SET UDF04=@TD005,UDF05=@TD006,UDF54=@TD010,UDF55=@TD008
       WHERE @TD003='0002' AND TK017=@TD001 AND TK018=@TD002
    SET NOCOUNT OFF
COMMIT TRANSACTION
如果原表两行记录,只会更序号为0002的记录,而我想要是0001和0002都会更新上去?不知道哪里错了请各位大神帮忙看看

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