CREATE TRIGGER [dbo].[TU_Price_Over_Under] ON [dbo].[Over_Under_Factor]
For  Update
AS 

Declare @Price  Money
Declare @Nu Bigint
Declare @Id Bigint
Declare @Type char(1)

  If Update(Price)   
  begin
    Select @Nu=i.AutoId ,@Price=Round(i.Price,0) , @Id = i.Id_Havaleh, @Type = i.Type
    from inserted i
    where AutoId=i.AutoId
    
    IF @Type = '0' 
    Begin
      Update  Sanad set Bedeh=@Price   Where (Nu_Over_Under=@Nu) And Type = @Type
      Update  sanad set Bestan=@Price  Where (Nu_Over_Under=@Nu) And Type = '1'
    End
    Else
    Begin
      Update  sanad set Bestan=@Price  Where (Nu_Over_Under=@Nu) And Type = @Type
      Update  Sanad set Bedeh=@Price   Where (Nu_Over_Under=@Nu) And Type = '0'
    end
  end
