Solved

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

Posted on 2014-09-12
2
177 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 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
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.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

815 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

12 Experts available now in Live!

Get 1:1 Help Now