-- اين تريگر به محض تغيير در قيمت هاسابقه ان را نگهداري مي کنند
CREATE TRIGGER [dbo].[TU_History_Price] ON [dbo].[Anbar]
After Update
AS 
If Update(Price_Kharid) Or Update(Price_Forosh) or Update(Price_Omdeh)
Begin
   Declare @Price_Kharid_New  Money
   Declare @Price_Omdeh_New   Money
   Declare @Price_Forosh_New  Money

   Declare @Anbar_Code        VarChar(3)
   Declare @Kala_Code         VarChar(15)

   Declare Cursor_Update Cursor For
   Select A_Code, K_code, Price_Kharid, Price_Forosh, Price_Omdeh From Inserted
   Open Cursor_Update
   Fetch Next From Cursor_Update Into @Anbar_Code, @Kala_Code, @Price_Kharid_New, @Price_Forosh_New, @Price_Omdeh_New
   while @@Fetch_Status = 0 
   Begin
      If @Price_Kharid_New <>0  Or  @Price_Omdeh_New <>0   Or  @Price_Forosh_New <>0
        Insert Into  Dbo.History_Price(A_Code,K_Code,Price_Kharid,Price_Forosh,         Price_Omdeh )
        Values(@Anbar_Code,@Kala_Code,@Price_Kharid_New,@Price_Forosh_New,         @Price_Omdeh_New)
        Fetch Next From Cursor_Update Into @Anbar_Code, @Kala_Code, @Price_Kharid_New,         @Price_Forosh_New, @Price_Omdeh_New
   End
   Close Cursor_Update
   Deallocate Cursor_Update
End
