Subject Re: [ib-support] SQL Question
Author R. Tulloch
Hi:

Thanks for all input.

Test several times and seems to work fine (along with other I
changed also).

I copied db and removed the update from records that had been
orphaned
before. Ran with new SP and no orphaned records as before.

One question which I have discussed with you previously (I think)
and is still happening:

At <--- below your suggestion INTO :MEMID DO (and the docs)
does not work. It SQL errors on the : and only works with

INTO MEMID DO

Other folks have told me I am full of BS when I asked this question
elsewhere.

SET TERM ## ;
CREATE PROCEDURE MEMBERDUESINVOICE (STARTDATE DATE, CLOSEDATE DATE )
AS
DECLARE VARIABLE MEMID INTEGER;
BEGIN
FOR SELECT M2.ID FROM MEMPAY2 M2
JOIN MEMBERS M ON M2.ID = M.ID AND M2.RENEW_DATE = M.RENEW_DTE
WHERE (M.STATUS_MEM = 'ACTIVE' OR M.STATUS_MEM = 'ASSOCIATE')
INTO MEMID DO <-----------
BEGIN
UPDATE MEMPAY2 M3
SET M3.REMIND_LET = CURRENT_DATE
WHERE M3.ID = :MEMID AND M3.RENEW_DATE >= :startdate
AND M3.RENEW_DATE <= :closedate
AND M3.DATE_PAID IS NULL
AND M3.REMIND_LET IS NULL
AND M3.RENEW_DATE IS NOT NULL;
END
END ##
SET TERM ; ##

In another one I just used:

JOIN MEMBERS M ON M2.ID = M.ID which selects all the child
records then updates only those that meet the UPDATE-WHERE criteria.

There is another field I can use to further limit M2:

JOIN MEMBERS M ON M2.ID = M.ID AND M2.YEARM2 = EXTRACT(YEAR FROM
current_date) AS YYYY

except I don't know how to extract here.

Thanks.

Best regards