Solved

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

Posted on 2014-09-12
2
174 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
2 Comments
 
LVL 39

Accepted Solution

by:
Kyle Abrahams earned 500 total points
Comment Utility
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
Comment Utility
Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Using MS SQL / SQLLite for iPhone  App 7 25
.htaccess file settings 4 31
Link SQL table to Webpage 9 35
Complex SQL 10 32
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now