| Author |
Topic |
|
sneupane
Starting Member
28 Posts |
Posted - 2010-04-06 : 16:36:18
|
| I want to combine the following queries:a.---------------Production BOM-----------------------------------------Select -- [Production BOM No_]-- ,[NO]-- ,[Quantity]-- ,[Unit of Measure Code] -- From BOMb.Combine BOM and Item Ledger using BOM.[Production BOM No_]= ItemLedger.[Item No_]-----------------------Item Ledger Entry------------------------------SELECT -- -- [Item No_]-- ,sum([Quantity]) as QuantityOnHand--FROM ItemLedger--Group By [Item No_]c. Combine BOM and Purchase using BOM.[No_]= Purchase.[No_]-----------------------Purchase Line Table-----------------------------SELECT -- [No_]-- ,[Unit of Measure]-- ,sum([Quantity])as QuantityOnPurchaseOrder-- -- FROM Purchase-- Where [Document Type]=1-- Group By [No_],[Unit of Measure]I would like a result in a single table combing all the queries.Waiting for suggestions.SAROJ |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sneupane
Starting Member
28 Posts |
Posted - 2010-04-06 : 17:15:44
|
| a. Query (a.) results Production BOM No_ No_B085A-D1012-075 B085A-00000-075B085A-D1012-105 B085A-00000-105N938A-D4005-180 C002A-00000-180N252A-00000-200 C003A-00000-200N252A-D1006-200 C003A-00000-200b.Query (b.) resultsItem No_ QuantityonHandZBL-1159-10 93.00000000000000000000R335I-00000-095 2.00000000000000000000DSCVB-P0000-000 10.00000000000000000000A601O-DV024-000 1.00000000000000000000MV-1821227-105 25.00000000000000000000SK-R122V-00000-100 0.00000000000000000000c. Query (c.) resultsNo_ QuantityonPurchaseOrderZSK-7001CO-13.5 5.00000000000000000000A171U-00000-000 8.00000000000000000000R269S-00000-060 1.00000000000000000000ZBL-3649B-10 98.00000000000000000000ZTF-1002-100 2993.00000000000000000000E103S-07913-000 2.00000000000000000000A063U-07750-000 23.00000000000000000000Now i want to use this result and create a query whereBOM.NO_= Sales.[Item.No_]BOM.NO_ = Purchase.[No]ThanksSAROJ |
 |
|
|
sneupane
Starting Member
28 Posts |
Posted - 2010-04-06 : 17:17:02
|
| Sorry. lets make it small. So i would like to work on combining 3 queries above.SAROJ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sneupane
Starting Member
28 Posts |
Posted - 2010-04-06 : 17:24:27
|
| BOM.NO_ [Item.No_] Purchase.[No]x y zSAROJ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sneupane
Starting Member
28 Posts |
Posted - 2010-04-06 : 17:26:03
|
| Production BOM No_ NO_ QuantityonHand QuantityonPurchaseOrdex y 0 0 Sorry this is correct formatSAROJ |
 |
|
|
sneupane
Starting Member
28 Posts |
Posted - 2010-04-06 : 17:28:04
|
| B085A-D1012-075 B085A-00000-075 10.00000000000000000000 8.00000000000000000000sorry to make you confused.SAROJ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sneupane
Starting Member
28 Posts |
Posted - 2010-04-06 : 17:49:10
|
| Sorry Tara to bring this confusion againI would like to get 4 columns from the result1. Production BOM No_2. NO_ 3. QuantityonHand4. QuantityonPurchaseOrderUsing BOM.NO_= Sales.[Item.No_]BOM.NO_ = Purchase.[No SAROJ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-04-06 : 18:07:07
|
Perhaps you're after something like this:SELECT b.[Production BOM No_], b.NO_, i.QuantityonHand, p.QuantityonPurchaseOrderFROM BOM bINNER JOIN ( SELECT [Item No_], sum([Quantity]) as QuantityOnHand FROM ItemLedger GROUP BY [Item No_]) i ON b.[Production BOM No_]= i.[Item No_]INNER JOIN ( SELECT [No_] ,sum([Quantity]) as QuantityOnPurchaseOrder FROM Purchase WHERE [Document Type]=1 GROUP BY [No_]) p ON b.[No_] = p.[No_] There are 10 types of people in the world, those that understand binary, and those that don't. |
 |
|
|
sneupane
Starting Member
28 Posts |
Posted - 2010-04-06 : 18:09:33
|
| Sample Data[Production BOM No_] [No_]R500 ZSK-100R600 ZSK-200R700 ZSK-300R800 ZSK-400R900 ZSK-500[Item No_] [QuantityonHand]ZSK-200 50ZSK-400 60ZSK-100 70[No_] [QuantityonPurchaseOrder]ZSK-100 50ZSK-200 80ZSK-300 90ZSK-400 70Result I needed[Production BOM No_] [No_] [QuantityonHand] [QuantityonPurchaseOrder]R500 ZSK-100 70 50R600 ZSK-200 50 80R800 ZSK-400 60 70SAROJ |
 |
|
|
sneupane
Starting Member
28 Posts |
Posted - 2010-04-06 : 18:36:53
|
| GROUP BY [Item No_]) iIn above statement I could not understand what is 'i' after the closing parenthesis. Would you please explain it to me?SAROJ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sneupane
Starting Member
28 Posts |
Posted - 2010-04-06 : 18:46:22
|
| woo thanks DBA in the making. I did it by your suggestion. You are the smarter one.SAROJ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
DBA in the making
Aged Yak Warrior
638 Posts |
Posted - 2010-04-06 : 19:18:06
|
Awww shucks. Thanx guys. There are 10 types of people in the world, those that understand binary, and those that don't. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|