I use SQL Anywhere 11.
I have the following view:
CREATE MATERIALIZED VIEW "DBA"."PointsAcc"( /* view_column_name, ... */ )
IN "SYSTEM" AS
select sum(PL.Points) AS Sum, DP.UserUID, COUNT(*) AS cnt
FROM Points DP
KEY JOIN PointLine PL
KEY JOIN PointHead PH
GROUP BY DP.UserUID
I have a trigger in PointLine that should select the sum from this view:
CREATE TRIGGER "WorkOnPoints" AFTER INSERT, DELETE
ORDER 1 ON "DBA"."Points"
REFERENCING OLD AS oldrow NEW AS newrow
FOR EACH ROW
BEGIN
declare @points integer;
set @points = (isnull((select isnull(Sum, 0)) FROM PointsAcc where UserUID = newrow.UserUID), 0))
END;
The @points variable now contains the sum from before the line was inserted or deleted. How can i get the updated sum from the view in the trigger?