Below is the trigger code im working on. I need to know a couple of things. One, is it okay to have declared variables in my trigger to store a calculated field's value? Two, is it okay to have multiple sets like i do in the code. any help would be great.
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER trigger calcFinancial
on dbo.tblPIW_DB1
for insert, update
as
update dbo.tblPIW_DB1
set Profit =
--these formulas pull data from both tables
case when (i.[fellthroughdate1] is null and i.[fellthroughdate2 is null]) then --formula
case when (i.[fellthroughdate1] is not null and i.[fellthroughdate2 is null]) then --formula
case when (i.[fellthroughdate1] is not null and i.[fellthroughdate2 is not null]) then --formula
end
from dbo.tblPIW_DB1
inner join INSERTED i
on tblPIW_DB1.[prop_num] = i.[prop_num]
inner join tblPIW_DB2
on i.[prop_num] = tblPIW_DB2.[prop_num]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER trigger calcFinancial
on dbo.tblPIW_DB1
for insert, update
as
update dbo.tblPIW_DB1
set Profit =
--these formulas pull data from both tables
case when (i.[fellthroughdate1] is null and i.[fellthroughdate2 is null]) then --formula
case when (i.[fellthroughdate1] is not null and i.[fellthroughdate2 is null]) then --formula
case when (i.[fellthroughdate1] is not null and i.[fellthroughdate2 is not null]) then --formula
end
from dbo.tblPIW_DB1
inner join INSERTED i
on tblPIW_DB1.[prop_num] = i.[prop_num]
inner join tblPIW_DB2
on i.[prop_num] = tblPIW_DB2.[prop_num]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO