Hi. I am using Sync framework to synchronize sales from clients to server and i have onmy table this trigger:
Create trigger triggerUpdateProductAmountAfterTurnoverInsert
on ProductTurnovers
after insert
AS
begin
declare
@id uniqueidentifier,
@positiveamount float,
@negativeamount float,
@day int,
@month int,
@year int,
@period datetime = CURRENT_TIMESTAMP;
declare insertcursor Cursor
for
select
ProductID,
PositiveAmount,
NegativeAmount,
DAY(Period) as day,
MONTH(Period) as month,
YEAR(Period) as year
from
inserted
set nocount on;
open insertcursor;
fetch next from insertcursor
into @id, @positiveamount, @negativeamount, @day, @month, @year
while @@FETCH_STATUS = 0
begin
update
Products
set
Amount = Amount + (@positiveamount - @negativeamount),
AmountPurchased = AmountPurchased + @positiveamount,
AmountSold = AmountSold + @negativeamount
where
ID = @id;
select @period = CONVERT(datetime, cast(@year as varchar(4)) + '.' + cast(@month as varchar(2)) + '.' + cast(@day as varchar(2)), 102);
exec dbo.updateProductStockHistory @id, @period;
fetch next from insertcursor
into @id, @positiveamount, @negativeamount, @day, @month, @year
end;
close insertcursor;
deallocate insertcursor;
end;
GO
and after the synchronization a have noticed that the trigger was fired two times. (turnover amount was added twice)
When I tried to insert in table ProductTurnovers manualy the trigger was fired only once.
Thank you for your replies and suggestions