Home > database >  Consult: use a trigger to the main table field updates for the child table first line values
Consult: use a trigger to the main table field updates for the child table first line values

Time:09-29

The main table: rdrecord32 (ID, cDefine1)
Child table: rdrecords32 (ID, iordercode irowno - line number)

 create TRIGGER [dbo] [cscs111] ON [dbo] [rdrecord32] 
FOR INSERT, UPDATE
AS
DECLARE @ ID VARCHAR (100)
SELECT @ ID=ID FROM Inserted

The begin
UPDATE a
SET
A.c Define1=b.i ordercode

The FROM rdrecord32 a join rdrecords32 b on Anderson, d=b.i d WHERE b.i d=@ ID and isnull (a.c Define1, ' ')!=' 'and b.i rowno=1
End



The above statement is executed successfully, but after testing cDefine1 still empty, a great god please help to see where there's a problem? Thank you very much!

CodePudding user response:

 and isnull (a.c Define1, ' ')!="

This condition not to say that update is not null field, if is empty, will not be updated, try to remove the conditions of the effect

CodePudding user response:

This is an update of the problem, carefully study the update usage, you can do this,
  • Related