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 |
|
schicmg
Starting Member
2 Posts |
Posted - 2008-10-15 : 18:10:22
|
I'm new to this... The following query is intended to populate a dispensing record report. Desired result is a line for each item on a bill of material, and if an allocation exists, the allocation details. IF no allocation exists, blank space to write in the data. The left outer join is returing duplicate entries and mixing data bewteen the two tables. Any pointers?Mike SELECT BP62FPRO.FMA.MORD, BP62FPRO.FMA.MPROD, BP62FPRO.FMA.MQREQ, BP62FPRO.ELAL01.AORD, BP62FPRO.ELAL01.APROD, BP62FPRO.ELAL01.ALOC, BP62FPRO.ELAL01.ALOT, BP62FPRO.ELAL01.LACNTR, BP62FPRO.IIML01.IDESC, FROM BP62FPRO.FMA, BP62FPRO.IIML01 Left Outer Join "BP62FPRO"."ELAL01" on( "BP62FPRO"."FMA"."MORD" = "BP62FPRO"."ELAL01"."AORD" ) WHERE (BP62FPRO.FMA.MPROD = BP62FPRO.IIML01.IPROD ) and (BP62FPRO.FMA.MPROD = BP62FPRO.ELAL01.APROD ) AND (BP62FPRO.FMA.MORD = BP62FPRO.ELAL01.AORD) |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-16 : 01:47:56
|
quote: Originally posted by schicmg I'm new to this... The following query is intended to populate a dispensing record report. Desired result is a line for each item on a bill of material, and if an allocation exists, the allocation details. IF no allocation exists, blank space to write in the data. The left outer join is returing duplicate entries and mixing data bewteen the two tables. Any pointers?Mike SELECT BP62FPRO.FMA.MORD, BP62FPRO.FMA.MPROD, BP62FPRO.FMA.MQREQ, BP62FPRO.ELAL01.AORD, BP62FPRO.ELAL01.APROD, BP62FPRO.ELAL01.ALOC, BP62FPRO.ELAL01.ALOT, BP62FPRO.ELAL01.LACNTR, BP62FPRO.IIML01.IDESC, FROM BP62FPRO.FMA, BP62FPRO.IIML01 Left Outer Join "BP62FPRO"."ELAL01" on( "BP62FPRO"."FMA"."MORD" = "BP62FPRO"."ELAL01"."AORD" ) WHERE (BP62FPRO.FMA.MPROD = BP62FPRO.IIML01.IPROD ) and (BP62FPRO.FMA.MPROD = BP62FPRO.ELAL01.APROD ) AND (BP62FPRO.FMA.MORD = BP62FPRO.ELAL01.AORD)
does more than allocation exists for any line item? i.e is relationship 1 to many? if else you need to user GROUP BY to return 1 line per item |
 |
|
|
schicmg
Starting Member
2 Posts |
Posted - 2008-10-16 : 09:09:09
|
| Thanks for your interest.Sample data:FMA (order bill of material) MORD MPROD MQREQ112422 1 100112422 2 100112422 3 400ELAL01 (allocations for order) AORD APROD ALOT ALOC112422 1 A wbb112422 1 B wbb112422 2 c wbbIIML01 (product master table) IPROD IDESC1 paper2 plastic3 totedesired result MPROD IDESC MQREQ A LOT ALOC1 paper 100 A wbb B wbb2 plastic 100 C wbb3 tote 400 current resultMPROD IDESC MQREQ A LOT ALOC1 paper 100 A wbb1 paper 100 B wbb1 paper 100 C wbb2 plastic 100 A wbb2 plastic 100 B wbb2 plastic 100 C wbband all the various combinations |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-16 : 09:31:00
|
Start by rewriting your query according to ANSI styleSELECT FMA.MORD, FMA.MPROD, FMA.MQREQ, ELAL01.AORD, ELAL01.APROD, ELAL01.ALOC, ELAL01.ALOT, ELAL01.LACNTR, IIML01.IDESC,FROM BP62FPRO.FMAINNER JOIN BP62FPRO.IIML01 ON IIML01.IPROD = FMA.MPRODLEFT JOIN BP62FPRO.ELAL01 ON ELAL01.AORD = FMA.MORD AND ELAL01.APROD = FMA.MPROD AND ELAL01.AORD = FMA.MORD E 12°55'05.63"N 56°04'39.26" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-16 : 12:31:59
|
quote: Originally posted by schicmg Thanks for your interest.Sample data:FMA (order bill of material) MORD MPROD MQREQ112422 1 100112422 2 100112422 3 400ELAL01 (allocations for order) AORD APROD ALOT ALOC112422 1 A wbb112422 1 B wbb112422 2 c wbbIIML01 (product master table) IPROD IDESC1 paper2 plastic3 totedesired result MPROD IDESC MQREQ A LOT ALOC1 paper 100 A wbb B wbb2 plastic 100 C wbb3 tote 400 current resultMPROD IDESC MQREQ A LOT ALOC1 paper 100 A wbb1 paper 100 B wbb1 paper 100 C wbb2 plastic 100 A wbb2 plastic 100 B wbb2 plastic 100 C wbband all the various combinations
seems like this is for reporting. If yes, the format that you're looking for can be easily achieved at front end. Just return data as it is now and use hide duplicates or suppress duplicates option available in reports. Which report application are you using? |
 |
|
|
|
|
|
|
|