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 |
|
msc_timor
Starting Member
11 Posts |
Posted - 2008-01-19 : 03:25:19
|
| hi, can anyone help on thishere's the situationi have tables as 1. items - contains itemid, description, price etc..2. shops - contains locationid, shopname, etc..3. sales - locationid, itemid, sale_qty 4. purchase - locationid, itemid, purchase_qtyi want shop wise item stock quantityfor individual shop i can query out but it dosent work for all shops at one goany suggestionswaitin'............................mipham |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-19 : 03:44:41
|
| try if this gives you desired result?SELECT s.shopname,i.description,SUM(sl.saleqty)-SUM(p.purchaseqty) AS StockFROM shops sINNER JOIN sales slON sl.locationid=s.locationidINNER JOIN purchase pON p.locationid=s.locationidAND p.itemid=sl.itemidINNER JOIN items iON i.itemid=sl.itemidGROUP BY s.shopname,i.description |
 |
|
|
msc_timor
Starting Member
11 Posts |
Posted - 2008-01-30 : 00:17:01
|
| hello, i tried this and also the outer joins, but dosent worksif i try the inner join,the only data common to both are outputas the case is that the item in sales may not be in the purchase and vica-versaand if i try the outer jointhe combination of all the items with locations is displayed which is also not a relevent data. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-30 : 00:40:58
|
| Can you specify your exact requirement with some sample data & expected o/p then? |
 |
|
|
|
|
|
|
|