Hallo Zusammen,
ich habe einen Trigger der zunächst 3 Werte berechnet(PCPlan, PCPrep,PCExec)
diese 3 berechneten Werte sollen dann addiert werden (PCTot). Ist das möglich? wenn ja, wo ist mein Fehler??
Mein Trigger:
CREATE TRIGGER [dbo].[TR_BaseData]
On [dbo].[Base]
After Insert, Update, Delete
As
Begin
Update Base
SET PCPlan=
case
when (select Inserted.HrsPlan from Inserted)<>0
AND (select Inserted.CstPerHrPlan from Inserted)<>0
then (select Inserted.HrsPlan*inserted.CstPerHrPlan from Inserted)
When (select Inserted.HrsPlan from Inserted)=0
Or (select Inserted.CstPerHrPlan from Inserted)=0
Then 0
End
Update Base
SET PCPrep=
case
when (select Inserted.HrsPrep from Inserted)<>0
AND (select Inserted.CstPerHrPrep from Inserted)<>0
then (select Inserted.HrsPrep*inserted.CstPerHrPrep from Inserted)
When (select Inserted.HrsPrep from Inserted)=0
Or (select Inserted.CstPerHrPrep from Inserted)=0
Then 0
End
Update Base
SET PCExec=
case
when (select Inserted.HrsExec from Inserted)<>0
AND (select Inserted.CstPerHrExec from Inserted)<>0
then (select Inserted.HrsExec*inserted.CstPerHrExec from Inserted)
When (select Inserted.HrsExec from Inserted)=0
Or (select Inserted.CstPerHrExec from Inserted)=0
Then 0
END
Update Base
SET PCTot=
case
when (select Inserted.PCPlan from Inserted)<>0
OR (select Inserted.PCPrep from Inserted)<>0
OR (select Inserted.PCExec from Inserted)<>0
then (select Inserted.PCPlan+Inserted.PCPrep+Inserted.PCExec from Inserted)
When (select Inserted.PCPlan from Inserted)=0
AND (select Inserted.PCPrep from Inserted)=0
AND (select Inserted.PCExec from Inserted)=0
Then 0
End
End
Hoffe mir kann jemand helfen
ich habe einen Trigger der zunächst 3 Werte berechnet(PCPlan, PCPrep,PCExec)
diese 3 berechneten Werte sollen dann addiert werden (PCTot). Ist das möglich? wenn ja, wo ist mein Fehler??
Mein Trigger:
CREATE TRIGGER [dbo].[TR_BaseData]
On [dbo].[Base]
After Insert, Update, Delete
As
Begin
Update Base
SET PCPlan=
case
when (select Inserted.HrsPlan from Inserted)<>0
AND (select Inserted.CstPerHrPlan from Inserted)<>0
then (select Inserted.HrsPlan*inserted.CstPerHrPlan from Inserted)
When (select Inserted.HrsPlan from Inserted)=0
Or (select Inserted.CstPerHrPlan from Inserted)=0
Then 0
End
Update Base
SET PCPrep=
case
when (select Inserted.HrsPrep from Inserted)<>0
AND (select Inserted.CstPerHrPrep from Inserted)<>0
then (select Inserted.HrsPrep*inserted.CstPerHrPrep from Inserted)
When (select Inserted.HrsPrep from Inserted)=0
Or (select Inserted.CstPerHrPrep from Inserted)=0
Then 0
End
Update Base
SET PCExec=
case
when (select Inserted.HrsExec from Inserted)<>0
AND (select Inserted.CstPerHrExec from Inserted)<>0
then (select Inserted.HrsExec*inserted.CstPerHrExec from Inserted)
When (select Inserted.HrsExec from Inserted)=0
Or (select Inserted.CstPerHrExec from Inserted)=0
Then 0
END
Update Base
SET PCTot=
case
when (select Inserted.PCPlan from Inserted)<>0
OR (select Inserted.PCPrep from Inserted)<>0
OR (select Inserted.PCExec from Inserted)<>0
then (select Inserted.PCPlan+Inserted.PCPrep+Inserted.PCExec from Inserted)
When (select Inserted.PCPlan from Inserted)=0
AND (select Inserted.PCPrep from Inserted)=0
AND (select Inserted.PCExec from Inserted)=0
Then 0
End
End
Hoffe mir kann jemand helfen