TR_MKTCREATIVE_IU_ORGANIZATIONCOST
Definition
Copy
CREATE trigger [dbo].[TR_MKTCREATIVE_IU_ORGANIZATIONCOST] on [dbo].[MKTCREATIVE]
after insert, update
not for replication
as
begin
set nocount on;
-- if we try to save an amount without explicitly setting an organization amount and an exchange rate,
-- copy the amount to the organization amount.
if update(COST)
begin
declare @ORGANIZATIONCURRENCYID uniqueidentifier = dbo.[UFN_CURRENCY_GETORGANIZATIONCURRENCY]();
update dbo.[MKTCREATIVE] set
[MKTCREATIVE].[ORGANIZATIONCOST] = [MKTCREATIVE].[COST],
[MKTCREATIVE].[BASECURRENCYID] = @ORGANIZATIONCURRENCYID,
[MKTCREATIVE].[CHANGEDBYID] = [MKTCREATIVE].[CHANGEDBYID],
[MKTCREATIVE].[DATECHANGED] = [MKTCREATIVE].[DATECHANGED]
from inserted
inner join dbo.[MKTCREATIVE] on inserted.ID = [MKTCREATIVE].[ID]
where [MKTCREATIVE].[CURRENCYEXCHANGERATEID] is null
and ([MKTCREATIVE].[BASECURRENCYID] is null or [MKTCREATIVE].[BASECURRENCYID] = @ORGANIZATIONCURRENCYID)
and ([MKTCREATIVE].[ORGANIZATIONCOST] <> [MKTCREATIVE].[COST] or [MKTCREATIVE].[COST] = 0);
end
end