Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
magdoomak
Starting Member
3 Posts |
Posted - 2010-08-15 : 06:35:51
|
| I have master and detailed table and as followsMaster: jv_date,jv_no,batch_codeDetail: jv_date,jv_no,debit_or_credit,amountValues in Detail table are:JV_DATE JV_NO DEBIT_OR_CREDIT AMOUNT10-MAY-2010 10101 D 500.0010-MAY-2010 10101 D 300.0010-MAY-2010 10101 D 200.0010-MAY-2010 10101 C 1000.0010-MAY-2010 10102 D 1200.0010-MAY-2010 10102 C 300.0010-MAY-2010 10102 C 200.0010-MAY-2010 10102 C 700.00The output should be like below10-MAY-2010 10101 D 1000.0010-MAY-2010 10101 C 1000.0010-MAY-2010 10102 D 1200.0010-MAY-2010 10102 C 1200.00Thanks in advance. |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-08-15 : 06:48:25
|
selectJV_DATE, JV_NO, DEBIT_OR_CREDIT, sum(AMOUNT) as amountfrom Detailtablegroup by JV_DATE, JV_NO, DEBIT_OR_CREDIT No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
magdoomak
Starting Member
3 Posts |
Posted - 2010-08-15 : 07:54:41
|
| Thanks for reply.But the problem is, in the detail table, amount goes to different account for the same jv number. It is as below:JV_DATE JV_NO DEBIT_OR_CREDIT ACCOUNT AMOUNT10-MAY-2010 10101 D 10001 500.0010-MAY-2010 10101 D 10002 300.0010-MAY-2010 10101 D 10003 200.0010-MAY-2010 10101 C 10004 1000.00JV_DATE JV_NO DEBIT_OR_CREDIT ACCOUNT AMOUNT10-MAY-2010 10102 C 10001 500.0010-MAY-2010 10102 C 10002 300.0010-MAY-2010 10102 C 10003 200.0010-MAY-2010 10102 D 10004 1000.00How can we write this query to sum the amount by debit or credit, so that at the end I will get only one debit and credit for each jv no. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-08-15 : 08:01:12
|
My given solution isn't grouping by ACCOUNT because you havn't posted it in your first post.So the query should exactly bring what you want.Did you try? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
magdoomak
Starting Member
3 Posts |
Posted - 2010-08-15 : 08:20:40
|
| I forgot to add this coloumn in my first post.Yes. I tried, it works fine. |
 |
|
|
|
|
|
|
|