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 |
|
kamal.A
Yak Posting Veteran
70 Posts |
Posted - 2008-04-05 : 15:48:42
|
| I have two tables. The table is below.Table name 1 : IncomeIncome RentMonth1500 Jan1500 Feb1500 AprTable name 2 : ExpenseExpense ExpMonth200 Jan300 Mar400 AprThe result table becomes (Profit=Income-Expense)Profit Month1300 Jan1500 Feb-300 Mar1100 AprBut I form the query by join the both Income and Expense tables to subtract the Income and Expense month wise. But one moth is in one table the same month is not in another table. For Example Feb month is in Income table, but not in Expense table.And Mar month is in Expense table and not in Income table. So how will I form the query to achieve my result table as i indicated above. Kindly help me.Kamal. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-05 : 16:22:12
|
| [code]INSERT INTO ResultTable (Profit,Month)SELECT ISNULL(i.Income,0)-ISNULL(e.Expense,0), ISNULL(i.RentMonth,e.ExpMonth) FROM Income iFULL OUTER JOIN Expense eON e.ExpMonth=i.RentMonth[/code] |
 |
|
|
kamal.A
Yak Posting Veteran
70 Posts |
Posted - 2008-04-07 : 09:59:49
|
| The query run perfectly. Thanks for your valuable help.Kamal. |
 |
|
|
|
|
|