CREATE   TRIGGER [dbo].[TU_Cheqe]	 ON [dbo].[Cheqe]
FOR Update
AS
  Declare @Guid_Sanad uniqueidentifier
  Declare @Ch_Price    Money

  if Update(Ch_Price ) begin
     -- تعريف يک فچ روي لينک چک و سند حسابداري
     Declare       ALCursor Cursor LOCAL FOR
     SELECT     acl.GuId_Sanad,Round(i.Ch_Price,0)
	  FROM        dbo.Acc_Cheqe_Link acl INNER JOIN
	                     Inserted i ON acl.Guid_Cheqe = i.Guid_Cheqe
	
     OPEN ALCursor
	  
     FETCH NEXT FROM ALCursor    INTO @Guid_Sanad,@Ch_Price
	 
     WHILE @@FETCH_STATUS = 0     BEGIN 
        Update Sanad set Bedeh=@Ch_Price Where Guid_Sanad=@Guid_Sanad And Bedeh <>0
        Update Sanad set Bestan=@Ch_Price Where Guid_Sanad=@Guid_Sanad And Bestan<>0
        FETCH NEXT FROM ALCursor    INTO @Guid_Sanad,@Ch_Price
     END
  

  CLOSE  ALCursor
  DEALLOCATE  ALCursor
end





