Subject | Re: Doing an UPDATE where the data source requires a join between two tables |
---|---|
Author | Milan Babuskov |
Post date | 2007-01-23T09:56:58Z |
--- mspencewasunavailable wrote:
EXECUTE BLOCK
DECLARE VARIABLE SLP date;
DECLARE VARIABLE LP date;
DECLARE VARIABLE AccID integer;
DECLARE VARIABLE ServID integer;
AS
BEGIN
FOR
Select S1."Acc ID", S1."Serv ID", S1."Last Performed", X.LP
FROM sched s1
inner join SCHED S on S."Acc ID" = S1."Acc ID"
and S."Serv ID" = S1."Serv ID"
inner join (select A."Acc ID" as ACCID, A."Serv ID" as SERVID,
max(A."Date") as LP
from artrans a
where A."Code" in (0, 1, 2, 10)
group by A."Acc ID", A."Serv ID") X
on S."Acc ID" = X.ACCID and S."Serv ID" = X.SERVID
where S."Last Performed" <> X.LP
into :accid, :servid, :slp, :lp
DO
update SCHED s set s."Last Performed" = :LP
where s."Acc ID" = :AccID and s."ServID" = :ServID;
--
Milan Babuskov
http://www.guacosoft.com
> I've been staring at this problem for some time, but can't seem toThis is a perfect case for EXECUTE BLOCK.
> make any progress. I'm using FB2. I have this select:
EXECUTE BLOCK
DECLARE VARIABLE SLP date;
DECLARE VARIABLE LP date;
DECLARE VARIABLE AccID integer;
DECLARE VARIABLE ServID integer;
AS
BEGIN
FOR
Select S1."Acc ID", S1."Serv ID", S1."Last Performed", X.LP
FROM sched s1
inner join SCHED S on S."Acc ID" = S1."Acc ID"
and S."Serv ID" = S1."Serv ID"
inner join (select A."Acc ID" as ACCID, A."Serv ID" as SERVID,
max(A."Date") as LP
from artrans a
where A."Code" in (0, 1, 2, 10)
group by A."Acc ID", A."Serv ID") X
on S."Acc ID" = X.ACCID and S."Serv ID" = X.SERVID
where S."Last Performed" <> X.LP
into :accid, :servid, :slp, :lp
DO
update SCHED s set s."Last Performed" = :LP
where s."Acc ID" = :AccID and s."ServID" = :ServID;
--
Milan Babuskov
http://www.guacosoft.com