Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hello friends...here Is My Query
SQL
select TRAN_AMOUNT AS CLOSING_BAL 
  From LOANTRAN 
 WHERE TRAN_DATE IN ( select AC_CLOSEDT from LNMASTER 
                       where AC_NO BETWEEN 100 AND 200 ) 
   AND ROWID IN ( SELECT MAX(ROWID) FROM LOANTRAN 
                   WHERE TRAN_ACNO BETWEEN 100 AND 200)


Actually problem is, I want to create a crystal report with some account no and their closing balance.

Here is Demo Of LOANTRAN Tbl...
TRAN_ACNO    TRAN_DATE    TRAN_AMOUNT
1             2/2/2001       2000
2             2/2/2001       1500
3             2/2/2001       3000
2             2/2/2001       3700
3             2/2/2001       4500


I want to select last transection of One Perticular TRAN_ACNO .. in Above Example there are two times entry of Ac.No 2 in a single day..That means The Amount 3700 Is a closing Balence Of Acount No 2...(Closing Balance Means Last transection of any Account on that Single Day.. Ac.No 3 has Closing Balance 4500) i want to select such Closing Balance from LOANTRAN table of Account no Between 100 AND 200...

Please help Me.....
Kumar
Oracle Developer
[DELETED]@yahoo.co.in

[edit]Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know - OriginalGriff[/edit]
[edit2]Just cleaned up the sql so that it's easier to parse visually - Marcus[/edit2]
Posted
Updated 28-Jan-11 5:13am
v5
Comments
ravitechguy 28-Jan-11 9:46am    
Do you have any other columns in LOANTRAN table which will record date entry into the table.
Indivara 28-Jan-11 9:46am    
How do you figure that 3700 is the closing balance? Do you have the time as well? (your example only has date)
ravitechguy 28-Jan-11 9:52am    
Try Below:
Select a.tran_amount, a.rowid
from
(select TRAN_AMOUNT AS CLOSING_BAL,
ROWID As Rownumber
From LOANTRAN
WHERE TRAN_DATE IN (select AC_CLOSEDT from LNMASTER where AC_NO BETWEEN 100 AND 200)
Order by ROWID) a
where a.rowid in (SELECT MAX(ROWID) FROM LOANTRAN WHERE TRAN_ACNO BETWEEN 100 AND 200)

1 solution

As long as you have the WHERE ... BETWEEN 100 AND 200 clauses in your sql, you are potentially going to get multiple rows returned. You'll need to find a way to narrow these blocks down to single row returns in order to get the entire query to return one row. I can't tell you what that should look like unless you provide a bit more info on the LNMASTER table.
 
Share this answer
 
Comments
kumar_jadhav 29-Jan-11 0:00am    
Thank You Marcus.....
fjdiewornncalwe 31-Jan-11 16:28pm    
Hey Kumar.. I think you "accidentally" hit 1 instead of 5 on the vote. (5 is good, BTW, 1 is not so good).. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900