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 |
|
dhinasql
Posting Yak Master
195 Posts |
Posted - 2011-08-24 : 01:52:23
|
| Friends,Please find my sample table belowtable1-------PurchaseId | Gross | Deduction | Amount101 | 1000 | 25 | 975102 | 2000 | 75 | 1925table2-------PurchaseId | Item | Qty | Price | Amount101 | A | 2 | 20 | 40101 | B | 1 | 60 | 60101 | CXYZ | 1 | 900 | 900 102 | B | 1 | 2000 | 2000 CXYZ is always a special Item.My Expected outputWhere PurchaseId = 101PurchaseID | Gross | Deduction | SpecialAmount101 | 1000 | 25 | 900 Where PurchaseId = 102PurchaseID | Gross | Deduction | SpecialAmount102 | 2000 | 75 | 0Thanks in advance. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-24 : 01:57:13
|
| [code]SELECT t1.PurchaseID, t1.Gross,t1.Deduction,COALESCE(t2.Amount,0) AS SpecialAmountFROM table1 t1LEFT JOIN table2 t2ON t2.PurchaseId = t1.PurchaseId AND t2.Item = 'CXYZ'[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
dhinasql
Posting Yak Master
195 Posts |
Posted - 2011-08-24 : 02:24:34
|
| Thanks. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-24 : 02:28:50
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|