Hi PHV
It didn't work. My situation was slightly more complicated than originally shown. I keep getting ACCESS doesn't recognize [tblA].[gYear] in query one when running from query 2
Even though query1 works fine as a stand alone. That's why I ended up storing to a temporary table.
There is a parameter in the Query to choose a year from the tTheAct table.
I'll try to show you what I have here. Not sure how it will look.
Query 1
SELECT tTheAct.actID, tTheAct.PID, tblA.SValue, tblA.FValue, ([tblA].[SValue]-[tblA].[FValue]) AS DIFVALUE, (([tblA].[SValue]-[tblA].[FValue])*(select [tblW].[W1] from tblW where [tblW].[WYear] = [tblA].[gYear])/100) AS CL, (([tblA].[SValue]-[tblA].[FValue])*(select [tblW].[W2] from tblW where [tblW].[WYear] = [tblA].[gYear])/100) AS SL, tblA.gYEAR, (select [tblW].[W1] from tblW where [tblW].[WYear] = [tblA].[gYear]) AS theW1, (select [tblW].[W2] from tblW where [tblW].[WYear] = [tblA].[gYear]) AS theW2
FROM tTheAct LEFT JOIN tblA ON tTheAct.actID = tblA. actID
WHERE (((tTheAct.S1OutCome)='WON') AND ((tTheAct.Finished)=True) AND ((Year([tTheAct].[S1Date]))=[myYear])) OR (((tTheAct.Finished)=True) AND ((tTheAct.S2OutCome)='WON') AND ((Year([tTheAct].[S2Date]))=[myYear])) OR (((tTheAct.Finished)=True) AND ((tTheAct.S3OutCome)='WON') AND ((Year([tTheAct].[S3Date]))=[myYear])) OR (((tTheAct.Finished)=True) AND ((tTheAct.S4OutCome)='WON') AND ((Year([tTheAct].[S4Date]))=[myYear])) OR (((tTheAct.Finished)=True) AND ((tTheAct.S5OutCome)='WON') AND ((Year([tTheAct].[Stage5Date]))=[myYear])) OR (((tTheAct.Finished)=True) AND ((tTheAct.S6OutCome)='WON') AND ((Year([tTheAct].[S6Date]))=[myYear]))
GROUP BY tTheAct.actID, tTheAct.PID, tblA.SValue, tblA.FValue, tblA.gYEAR;
Table tTheAct
actID | PID | S1OutCome | S1Date | S2OutCome | S2Date|S3OutCome | S3Date| S4OutCome | S4Date| S5OutCome | S5Date| S6OutCome | S6Date| Finished
data rows :
|1, 1 , ‘LOOSE’,#01/01/1993#,’WON’,#03/03/19997#, RUN’,#01/01/1998#,’WON’,#03/03/1999#,,,,True |
|2, 1 , ‘SKIP’,#01/01/1999#,’WON’,#03/03/2004#,,,,,,,,True |
|3, 2 , ‘HOP’,#01/01/1996#,’WON’,#03/03/1997#,,,,,,,,True |
|4, 2 , ‘JUMP’,#01/01/1999#,’WON’,#03/03/2004#,,,,,,,,True |
Table tblA A
actID | PID | Svalue|Fvalue|gYear|
actID PID Year Svalue Fvalue
|1, 1, 1997, 34, 10 |
|1, 1, 1998, 12, 21 |
|2, 1, 1999, 60 , 30 |
|2, 1, 2000, 40, 20 |
|2, 1, 2001, 50, 40 |
|3, 2, 1996, 20, 11 |
|3, 2, 1997, 20, 13 |
|4, 2, 1999, 80, 40 |
|4, 2, 2000, 100, 60 |
|5, 3, 2001, 24, 12 |
|6 , 4, 1999, 30, 20 |
tblW
|WD |Year| W1| W2|
|1, 1999, 10, 20 |
|2, 2000, 20, 40 |
|3, 2001, 30, 60 |
query2 wont run
TRANSFORM Sum(Query1.CL) AS SommeDeaCL
SELECT Query1.actID, Query1.PIDFROM Query1
GROUP BY Query1.actID, Query1.PID