现在触发器看起来像这样,它部分工作
我的触发器看起来像这样
ALTER trigger [dbo].[tr_EligebilityCheck]
on [dbo].[Clients]
for INSERT,update
as
BEGIN
UPDATE Clients
SET
StatusID = 5
WHERE
ClientID IN (Select ClientID
from Clients c
join inserted --ADD THIS JOIN
on inserted.ClientID = c.ClientID
join IncomeEligibility i
on c.HshldSize = i.HshldSize
where StatusID in (1,2)
and WIC = 0
and (c.CategCode = 'SR'
and ((MonthlyYearly = 'month' and c.AnnualHshldIncome >= i.SeniorMo)
or (c.AnnualHshldIncome >= i.SeniorYr and MonthlyYearly ='year'))
and DATEDIFF(YEAR,DOB,GETDATE()) < 60)
or
(c.CategCode = 'CH'
and ((MonthlyYearly = 'month' and c.AnnualHshldIncome >= i.WomanChildMo)
or (c.AnnualHshldIncome >= i.WomanChildYr and MonthlyYearly ='year'))
and DATEDIFF(YEAR,DOB,GETDATE()) > 6))
update Clients
set StatusID = 4
where WIC =1
from Clients --ADD THIS FROM STATEMENT
join inserted --ADD THIS JOIN
on inserted.ClientID = Clients.ClientID
END
当我使用 CategCode = 'SR' 插入客户端时,它仅检查 DOB 并在客户端小于 60 岁时触发,但如果客户端年龄较大,则不检查
and ((MonthlyYearly = 'month' and c.AnnualHshldIncome >= i.SeniorMo)
or (c.AnnualHshldIncome >= i.SeniorYr and MonthlyYearly ='year'))
如果我插入带有 CategCode = 'CH' 的客户端,它会检查收入但没有检查 DOB。