Solved

SQL - How can I get the replacement part description on a query

Posted on 2014-09-12
2
180 Views
Last Modified: 2014-09-12
I have a part_code and a part_desc (Description) and a rep_part(Replacement).  There is no specific field in the database for a replacement part description.  How could I get that?  It is another part of the part master.

Example

Partmaster for Part_code 1234
part_code = 1234 Part_Desc = Numbers  Rep_part = ABCD

Partmaster for Part_Code ABCD
part_code = ABCD Part_Desc = Letters Rep_part NULL

In this example the rep_part ABCD in the part master would have a description of Letters

How can I get those on this query?



SELECT DISTINCT 
                      ediorderrors.order_numb, CAST(ediorderrors.item_no AS INT) AS line_numb, ediorderrors.error_desc, CAST(ediord.cust_code AS int) AS cust_code, ediord.loaddt, 
                      ediord.part_code AS UPC_CODE, partmstr.part_code AS PART_CODE, partmstr.part_desc AS DESCRIPTION, partmstr.uom AS UOM, ediord.shipto_code, 
                      ordhead.shipname, ediord.qty, partmstr.rep_part,ordhead.order_numb,rep2
FROM         ordhead INNER JOIN
                      ediord ON ordhead.cust_po = ediord.cust_po RIGHT OUTER JOIN
                      ediorderrors ON ediord.item_no = ediorderrors.item_no AND ediord.cust_po = ediorderrors.order_numb LEFT OUTER JOIN
                      ediorditem ON ediorditem.item_no = ediord.item_no AND ediorditem.cust_po = ediord.cust_po LEFT OUTER JOIN
                      partmstr ON partmstr.upc_code = ediord.part_code
WHERE     (ediorderrors.cust_code IS NOT NULL) AND (ediord.cust_code <> 'ZZZZZ') AND (ediord.cust_code <> 'PETLAN') AND (ediord.loaddt BETWEEN '09/11/14' AND '09/12/14') AND 
                      (ediord.cust_code <> '068775311CUSPRD') AND error_desc <> 'This is an invalid part ... Please Re-enter.'

Open in new window

0
Comment
Question by:gpsdh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 40319757
join to the table again.  I'm doing it as a left join in case you don't have replacement parts in some cases:

select
<fields>
,isnull(Replacement.Part_Desc, '') ReplacementPartDescription
from
<tables>
left join  partmstr Replacements ON partmstr.Rep_part = Replacements.part_code
WHERE
...
0
 

Author Closing Comment

by:gpsdh
ID: 40319830
Thanks!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Format Date fields 11 64
Does INTERSECT return opposite from FULL OUTER JOIN? 4 41
SQL Query 9 29
sql trace 4 28
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question