Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-09-12
2
Medium Priority
?
182 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.

715 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