CREATE TRIGGER [dbo].[TU_RepEkhtetam] ON [dbo].[RepEkhtetam] 
FOR UPDATE
AS

  Declare @Parent Smallint
  Declare @SumBedeh Money
  Declare @SumBestan Money

  Declare CursorUpdate Cursor For
  Select Parent_Code From Deleted
  Open CursorUpdate
  Fetch Next From  CursorUpdate Into @Parent
  While @@Fetch_Status = 0 
  Begin
    if Update(Bedeh) or Update(Bestan)
    begin
        Select @Sumbedeh= Sum(Bedeh) From RepEkhtetam Where Parent_Code = @Parent
        Select @Sumbestan= Sum(Bestan) From RepEkhtetam Where Parent_Code =@Parent
        Update RepEkhtetam Set Bedeh = @SumBedeh, Bestan = @SumBestan Where Autoid = @Parent
    end
    Fetch Next From  CursorUpdate Into @Parent
  End
  Close CursorUpdate
  Deallocate CursorUpdate
