views:

345

answers:

1

I have a couple of tables that are transaction tables, and I would like to make a simple pivot chart for comparative balances....which happen to be the last record of each of these tables in a field called "balance".

so i know how to populate this on a form using a SQL statement, rs.movelast, but i do not know how to get to the pivot chart without having this into a table....

thanks!

EDIT:

This is what I used! Thanks Remou!

(SELECT TOP 1 TransactionID, Balance  
FROM tblTrans001
ORDER BY TransctionID  DESC) 
UNION  
(SELECT TOP 1 TransactionID,  Balance  
FROM tblTransaction02 
ORDER BY TransactionID DESC) 
UNION
(SELECT TOP 1 TransactionID, Balance
FROM Tranaction03
ORDER BY TransID DESC) 

Now I just need to find a way to insert a text string into the corresponding fields that identifies what table the value is coming from.

for example, the above query returns

TransID     Balance
123         $1000.00
234         $20000.00
345         $300000.00

and I need:

TransID     Balance        Table/Account
123         $1000.00       tblTransaction01
234         $20000.00      tblTransaction02
345         $300000.00     tblTransaction03

thanks!

+3  A: 

What do you define last record? Let us say it is the date created and that the date created is unique, then you could use the SQL below. Note that the parentheses are important.

(SELECT TOP 1 CrDate , Balance , "TranA" As FromTable
FROM  TransactionsA
ORDER BY  CrDate DESC)
UNION 
(SELECT TOP 1 CrDate , Balance , "TranB" As FromTable
FROM  TransactionsB 
ORDER BY  CrDate DESC)
Remou
once again Remou, that worked fine! And I appreciate it as always! That was actually the first time I ever put a UNION query to use....thanks!
Justin
it was a little different than just a date, actually there is a transID in both tables, but the above method worked fine! thanks!
Justin
@Remou: one question, when I use the above method on 8 different tables, it works and I get the correct value for each one. The trouble is there is nothing in the resulting table that signifies which table it is coming from. Is there an expression I could add to this to allow me to insert a text value ( I am using a TransID instead of date, and the resulting table is causing the ORDER BY to list by transID of each table which always will change
Justin
@Justin I am not quite sure I catch your meaning, but I have added a note above.
Remou
you did, because that was exactly it! sorry did not know it was so simple! thanks!
Justin