-- Get first timers for 1997 SELECT AcctNum, SUM(Amount) AS Amount, 1997 AS giftyear FROM mytable WHERE GiftDate BETWEEN '1997/01/01' AND '1997/12/31 23:59:59' AND AcctNum NOT IN ( SELECT AcctNum FROM mytable WHERE GiftDate < '1997/01/01' ) GROUP BY AcctNum -- The same group's contributions after 1997 SELECT AcctNum, SUM(Amount) AS Amount, DATEPART(Year, GiftDate) AS giftyear FROM mytable WHERE GiftDate > '1997/12/31 23:59:59' AND AcctNum IN ( SELECT AcctNum FROM mytable WHERE GiftDate BETWEEN '1997/01/01' AND '1997/12/31 23:59:59' ) AND AcctNum NOT IN ( SELECT AcctNum FROM mytable WHERE GiftDate < '1997/01/01' ) GROUP BY AcctNum, DATEPART(Year, GiftDate)>Cool VFP code <bg>
SELECT AcctNum, SUM(Amount) AS Amount, 1997 AS year ; >> FROM mytable ; >> WHERE Year(GiftDate) = 1997 ; >> AND AcctNum NOT IN ( ; >> SELECT AcctNum FROM mytable ; >> WHERE Year(GiftDate) < 1997 ; >> GROUP BY AcctNum ; >> INTO CURSOR crsGift1997 NOFILTER >> >>SELECT AcctNum, SUM(Amount) AS Amount, Year(GiftDate) AS year ; >> FROM mytable ; >> WHERE Year(GiftDate) > 1997 ; >> AND AcctNum IN ( ; >> SELECT AcctNum FROM crsGift1997 ); >> GROUP BY AcctNum, Year ; >> INTO CURSOR crsGiftAfter NOFILTER >>>>