


CREATE trigger [dbo].[update_price1] on [dbo].[purchase_supply_product] for update
as 
   
begin
declare @newprice decimal(18,4)
declare @oldprice decimal(18,4)
select @newprice=price from inserted
select @oldprice=price from deleted
if(@newprice!=@oldprice)
begin
 
 
 insert into bps_historyprice (pid,price,adddate,pricedate,supplyname,minnum,maxnum,pricedateto)
 select proid,price,GETDATE(), pricedatefrom,sname,minnum,maxnum,pricedateto from inserted 
 
 end
 end




CREATE trigger [dbo].[insert_price1] on [dbo].[purchase_supply_product] for insert
as 
   

  insert into bps_historyprice (pid,price,adddate,pricedate,supplyname,minnum,maxnum,pricedateto)
 select proid,price,GETDATE(), pricedatefrom,sname,minnum,maxnum,pricedateto from inserted 
  







CREATE trigger [dbo].[delete_price1] on [dbo].[purchase_supply_product] for delete
as 
   
 insert into bps_historyprice (pid,price,adddate,pricedate,supplyname,minnum,maxnum,pricedateto)
 select proid,price,GETDATE(), pricedatefrom,sname,minnum,maxnum,pricedateto from deleted 
  





















CREATE trigger [dbo].[insert_price2] on [dbo].[purchase_categories] for insert
as 
  
 
begin
 insert into bps_historyprice (pid,price,adddate,pricedate,supplyname)
 select id,price,GETDATE(),  GETDATE() ,supplyname from inserted where iscat=0
 end

GO


CREATE trigger [dbo].[update_price2] on [dbo].[purchase_categories] for update
as 
  
 
begin
declare @newprice decimal(18,4)
declare @oldprice decimal(18,4)
select @newprice=price from inserted
select @oldprice=price from deleted
if(@newprice!=@oldprice)
begin
 insert into bps_historyprice (pid,price,adddate,pricedate,supplyname)
 select id,price,GETDATE(), GETDATE(),supplyname from inserted  where iscat=0
 end
 end

GO



