LambtonWorm
Registered User.
- Local time
- Today, 20:49
- Joined
- Jun 24, 2012
- Messages
- 12
Hi,
I have a form with many slow and cumbersome dLookup formulae in textboxes. I want to replace it with a neat and dynamic query subform.
For this I need to add the numerical results of two queries in something analagous to an inner join. But inner joins only exist for tables, and you can't establish relationships between queries.
The two queries are similar, but have to be separate because the filter conditions on the 'Time Sent' field are mutually exclusive, i.e. no overlap.
Both queries return a 'Strategy' field. I would want to add the respective 'xyz_USDPNL' results of the two queries whereever 'Strategy' is identical, or assume zero when not present.
Here is the SQL for the two queries. They work fine so there's nothing to troubleshoot. 'dCutoff()' just grabs a constant.
Query 1:
Query 2:
Please could someone point me in the right direction?
Is there a way of rewriting and combining the queries? (There's more to add, this is just the start..) Or do i need to create a temporary table every time this is refreshed? Or is it impossible?
Many Thanks!
I have a form with many slow and cumbersome dLookup formulae in textboxes. I want to replace it with a neat and dynamic query subform.
For this I need to add the numerical results of two queries in something analagous to an inner join. But inner joins only exist for tables, and you can't establish relationships between queries.
The two queries are similar, but have to be separate because the filter conditions on the 'Time Sent' field are mutually exclusive, i.e. no overlap.
Both queries return a 'Strategy' field. I would want to add the respective 'xyz_USDPNL' results of the two queries whereever 'Strategy' is identical, or assume zero when not present.
Here is the SQL for the two queries. They work fine so there's nothing to troubleshoot. 'dCutoff()' just grabs a constant.
Query 1:
Code:
SELECT CLng([Time Sent]-0.5+dCutoff()) AS TradeDate, [Security] & " " & [Family] & "_" & [TrigInterval] AS Strategy, Sum([Contracts]*([Spot]-[TradedPrice])*[tblStatic]![PointValue]-Abs([Contracts])*[tblStatic]![ClearingCosts])*[FXSpot] AS NEW_USDPNL
FROM tblFX INNER JOIN (tblStatic INNER JOIN tblTrades ON tblStatic.Asset = tblTrades.Security) ON tblFX.KeyCcy = tblStatic.CCY
GROUP BY CLng([Time Sent]-0.5+dCutoff()), [Security] & " " & [Family] & "_" & [TrigInterval], tblTrades.Confirmed, tblFX.FXSpot
HAVING (((CLng([Time Sent]-0.5+dCutoff()))=Date()) AND ((tblTrades.Confirmed)=Yes));
Query 2:
Code:
SELECT [Security] & " " & [Family] & "_" & [TrigInterval] AS Strategy, Sum([StartDayPosn]*([Spot]-[PrevClose])*[tblStatic]![PointValue]-Abs([StartDayPosn])*[tblStatic]![ClearingCosts])*[FXSpot] AS OLD_USDPNL
FROM tblFX INNER JOIN (tblStatic INNER JOIN tblTrades ON tblStatic.Asset = tblTrades.Security) ON tblFX.KeyCcy = tblStatic.CCY
GROUP BY CLng([Time Sent]-0.5+dCutoff())<Date(), [Security] & " " & [Family] & "_" & [TrigInterval], tblTrades.Confirmed, tblFX.FXSpot
HAVING (((CLng([Time Sent]-0.5+dCutoff())<Date())=Yes) AND ((tblTrades.Confirmed)=Yes));
Please could someone point me in the right direction?
Is there a way of rewriting and combining the queries? (There's more to add, this is just the start..) Or do i need to create a temporary table every time this is refreshed? Or is it impossible?
Many Thanks!