Author |
Topic |
Ristos85
Starting Member
8 Posts |
Posted - 2013-12-09 : 05:36:41
|
Hello,I have a BOM table with all finished item receipes and semi items receipes. What I would like help on is to create a query where semi item materials are also listed in finished item receipe. Please see link for sample.I could also add a column ItemType where 1 means that it's material and 2 means it's semi itemhttp://web.zone.ee/ristos85/bomquery.jpgAny ideas/hints how to create this?best regards,Risto |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-12-09 : 06:44:25
|
do you mean this?SELECT COALESCE(t1.BOMNo,t.BOMNo) AS BOMNo,t.MaterialNo,t.MaterailDescription,t.QuantityFROM BomTable tLEFT JOIN BOMTable t1ON t.BOMNo = t1.MaterialNo ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Ristos85
Starting Member
8 Posts |
Posted - 2013-12-09 : 07:56:30
|
This is exactly what I was looking for. Thank you visakh16, you saved my day quote: Originally posted by visakh16 do you mean this?SELECT COALESCE(t1.BOMNo,t.BOMNo) AS BOMNo,t.MaterialNo,t.MaterailDescription,t.QuantityFROM BomTable tLEFT JOIN BOMTable t1ON t.BOMNo = t1.MaterialNo ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-12-09 : 08:41:10
|
you're welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Ristos85
Starting Member
8 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-12-09 : 09:39:20
|
[code]SELECT COALESCE(t2.BOMNo,t1.BOMNo,t.BOMNo) AS BOMNo,t.MaterialNo,t.MaterailDescription,t.QuantityFROM BomTable tLEFT JOIN BOMTable t1ON t.BOMNo = t1.MaterialNoLEFT JOIN BOMTable t2ON t.BOMNo = t2.MaterialDescription[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Ristos85
Starting Member
8 Posts |
Posted - 2013-12-10 : 01:48:01
|
Almost. The third level article is listed nicely as article 0ABC material but materials that are in the third level article are not listed. How to get these materials (foil4, foil5) also below article 0ABC?http://web.zone.ee/ristos85/bomquery3.jpgquote: Originally posted by visakh16
SELECT COALESCE(t2.BOMNo,t1.BOMNo,t.BOMNo) AS BOMNo,t.MaterialNo,t.MaterailDescription,t.QuantityFROM BomTable tLEFT JOIN BOMTable t1ON t.BOMNo = t1.MaterialNoLEFT JOIN BOMTable t2ON t.BOMNo = t2.MaterialDescription ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
|
|
|
Ristos85
Starting Member
8 Posts |
Posted - 2013-12-10 : 03:43:11
|
Got it working! SELECT COALESCE (t2.BOMNo, t1.BOMNo, t.BOMNo) AS BOMNo, t.MaterialNo,t.MaterialDescription,t.QuantityFROM dbo.BomTable AS tLEFT OUTER JOINdbo.BomTable AS t1 ON t.BOMNo = t1.MaterialNoLEFT OUTER JOINdbo.BomTable AS t2 ON t1.BOMNo = t2.MaterialNo |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-12-10 : 05:43:30
|
Cool------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|