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 |
ravininave
Posting Yak Master
111 Posts |
Posted - 2012-03-14 : 03:52:02
|
My Table Details1] Table Name : APPMASTFields :AppMstIDAppMstNameMainID2] Table Name : PayReportsFields :AppMstIDNetPay3] Table Name : IncExpMastFields :AppMstIDAmountI've member details in APPMAST Member's Payout in PAYREPORTS table& Amount Paid in INCEXPMAST table.Actually, there are many members with same name e.g. there is a Member with Name 'abc' and his ID is say 2,10,23,45,105. Means 'abc' has 5 IDs.Upto Now, to view all Payments - Paid = Balance Details I Used query like :Select *,(Payout-Paid) as Balance from (Select a.appmstid,(Select appmstname from appmast where appmstid = a.appmstid) as ClientName,sum(a.NetPay) as Payout,(Select coalesce(sum(Amount),0) from IncExpMast where appmstid = a.appmstid) as Paid from payreports a group by a.appmstid) Test Order by balance;But, by using this method in My statement I get 'abc's record for 5 times and I need it at once. So, I thought about to club his ID from Main Table and then Added new column as MAINID in APPMAST TABLE.In Appmast I update all MAIN ID of 'abc' with 2. Means 2 is the Main ID of all 5 IDs. Now the task is to modify above query and to show Payment of 'abc' at once only.How to do this.????VB6/ASP.NET------------------------http://www.nehasoftec.com |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-03-14 : 07:43:10
|
Would this work for you?SELECT a.appmstid, a.appmstname AS ClientName, ISNULL(SUM(p.NetPay),0) AS Payout, ISNULL(SUM(i.Amount),0) AS Paid, ISNULL(SUM(p.NetPay),0) - ISNULL(SUM(i.Amount),0) AS BalanceFROM APPMAST a LEFT JOIN PayReports p ON p.appmstid = a.appmstid LEFT JOIN IncExpMast i ON i.appmstid = a.appmstidGROUP BY a.appmstid, a.appmstnameORDER BY Balance; |
 |
|
ravininave
Posting Yak Master
111 Posts |
Posted - 2012-03-14 : 07:54:13
|
quote: Originally posted by sunitabeck Would this work for you?SELECT a.appmstid, a.appmstname AS ClientName, ISNULL(SUM(p.NetPay),0) AS Payout, ISNULL(SUM(i.Amount),0) AS Paid, ISNULL(SUM(p.NetPay),0) - ISNULL(SUM(i.Amount),0) AS BalanceFROM APPMAST a LEFT JOIN PayReports p ON p.appmstid = a.appmstid LEFT JOIN IncExpMast i ON i.appmstid = a.appmstidGROUP BY a.appmstid, a.appmstnameORDER BY Balance;
The main problem is to show payment using MAINIDVB6/ASP.NET------------------------http://www.nehasoftec.com |
 |
|
ravininave
Posting Yak Master
111 Posts |
Posted - 2012-03-22 : 15:03:12
|
hey no one is replying.......VB6/ASP.NET------------------------http://www.nehasoftec.com |
 |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-03-22 : 20:00:42
|
quote: The main problem is to show payment using MAINID
Without some sample data, it is hard for me to visualize what you are after. If you post your typical input and the expected output, you would get better and faster responses.Regardless, is it one of these?SELECT a.appmstid, a.MainID, a.appmstname AS ClientName, ISNULL(SUM(p.NetPay),0) AS Payout, ISNULL(SUM(i.Amount),0) AS Paid, ISNULL(SUM(p.NetPay),0) - ISNULL(SUM(i.Amount),0) AS BalanceFROM APPMAST a LEFT JOIN PayReports p ON p.appmstid = a.appmstid LEFT JOIN IncExpMast i ON i.appmstid = a.appmstidGROUP BY a.appmstid, a.MainID, a.appmstnameORDER BY Balance; Or perhaps this?SELECT a.MainID, a.appmstname AS ClientName, ISNULL(SUM(p.NetPay),0) AS Payout, ISNULL(SUM(i.Amount),0) AS Paid, ISNULL(SUM(p.NetPay),0) - ISNULL(SUM(i.Amount),0) AS BalanceFROM APPMAST a LEFT JOIN PayReports p ON p.appmstid = a.appmstid LEFT JOIN IncExpMast i ON i.appmstid = a.appmstidGROUP BY a.MainID, a.appmstnameORDER BY Balance; |
 |
|
|
|
|
|
|