URGENT: Query question

princess15s

Registered User.
Local time
Today, 20:25
Joined
Aug 2, 2001
Messages
15
Is it very hard to pull a value from a query into another query and use that value to pull records from a table? PLEASE PLEASE PLEASE tell me how I could do this?
This is my situation; I have two tables, TBL1 containing original records, TBL2 containing the amended records. TBL1 & TBL2 are linked via Tnum. In QRY1 I’m selecting the records, which have been entered on a certain day from TBL1. Now what I want to do is Use the Tnum from QRY1 as the criteria in QRY2 and pull records from TBL2.
Do I make any sense? I want to see whether there is an amended version of the original record in TBL2 and if there is one then I want to pull it out using QRY2.
I’ve used the following in the criteria field of the Tnum in QRY2: “In (SELECT [Tnum] FROM QRY1” but it doesn’t work, so I tried the following and that doesn’t work neither:
SELECT (SELECT [tnum] FROM TSFM) AS tnum, IIf([fund]="SFM_1","QP-01","QP-02") AS Account, TradeAmendments.id, Sec.cusip, Sec.isin, Sec.sedol, Null AS [LOCAL], TradeAmendments.cpty, TradeAmendments.clr2, tblTradeTransactionType.TType, TradeAmendments.td, TradeAmendments.settles, TradeAmendments.q, TradeAmendments.tc, TradeAmendments.tp, TradeAmendments.tai, TradeAmendments.tax, Nz(IIf(([TType]="Buy" Or [TType]="L" Or [TType]="Buy Cover" Or [TType]="BC"),(([q]*[tp])+[tc]+[tai]+[tax]),(([q]*[tp])-[tc]-[tai]-[tax]))) AS NetAmount, ([cancel]="False"," ","x") AS CANCELLED, TradeAmendments.fund
FROM tblTradeTransactionType INNER JOIN (TradeAmendments INNER JOIN Sec ON TradeAmendments.id = Sec.id) ON tblTradeTransactionType.OrigTT = TradeAmendments.tt
WHERE (((TradeAmendments.tnum)) AND ((TradeAmendments.fund)="SFM_1" Or (TradeAmendments.fund)="SFM_2")) OR (((TradeAmendments.fund)="SFM_1" And (TradeAmendments.fund)="SFM_2"));
 
I believe this can be accomplished with just a single query.
If I understood your question correctly then this should work:

SELECT Tbl1.tnum, Tbl1.Date1, Tbl1.field1 AS OldValue, Tbl2.field1 AS NewValue
FROM Tbl1 LEFT JOIN Tbl2 ON Tbl1.tnum = Tbl2.tnum
WHERE (((Tbl1.Date1)=#{DateToLookFor}#) AND ((IIf([tbl1].[field1]=[tbl2].[field1],True,False))=False));

Hope this helps.
 
thank you but I've done it with three queries and it works so Im gonna leave it like that. Thanx a lot.
 

Users who are viewing this thread

Back
Top Bottom