TR_MKTPACKAGE_IU_ORGANIZATIONUNITCOST
Definition
Copy
CREATE trigger [dbo].[TR_MKTPACKAGE_IU_ORGANIZATIONUNITCOST] on [dbo].[MKTPACKAGE]
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(UNITCOST)
begin
declare @ORGANIZATIONCURRENCYID uniqueidentifier = dbo.[UFN_CURRENCY_GETORGANIZATIONCURRENCY]();
update dbo.[MKTPACKAGE] set
[MKTPACKAGE].[ORGANIZATIONUNITCOST] = [MKTPACKAGE].[UNITCOST],
[MKTPACKAGE].[BASECURRENCYID] = @ORGANIZATIONCURRENCYID,
[MKTPACKAGE].[CHANGEDBYID] = [MKTPACKAGE].[CHANGEDBYID],
[MKTPACKAGE].[DATECHANGED] = [MKTPACKAGE].[DATECHANGED]
from inserted
inner join dbo.[MKTPACKAGE] on inserted.ID = [MKTPACKAGE].[ID]
where [MKTPACKAGE].[CURRENCYEXCHANGERATEID] is null
and ([MKTPACKAGE].[BASECURRENCYID] is null or [MKTPACKAGE].[BASECURRENCYID] = @ORGANIZATIONCURRENCYID)
and ([MKTPACKAGE].[ORGANIZATIONUNITCOST] <> [MKTPACKAGE].[UNITCOST] or [MKTPACKAGE].[UNITCOST] = 0);
end
end