Question

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!

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top