2

Long story short I'm reasonably new to T-SQL, and I'm working on querying some info out of JD Edwards for our scheduling department. We're a manufacturing plant, and the table that contains our Part info and the components that go into making each part uses a single column for all components with multiple rows for each so we can have a single part with twenty rows, I have two problems with this query that have me a little stumped, the first is that I'd like to see one row per work order, that contains all of the part info, from the WO table I use our Finished part number in the following query:

Raw data from necessary columns for this WO & Finished Product:

WALITM                      IXLITM                      WADOCO
TF2-10426IA                 CF-S1094P-UL                800059
TF2-10426IA                 CF-S1094P-UL                800059
TF2-10426IA                 CF-S1094P-UL                800059
TF2-10426IA                 CF-S1094P-UL                800059
TF2-10426IA                 TE2-06718                   800059
TF2-10426IA                 TE2-06718                   800059
TF2-10426IA                 TE2-06718                   800059
TF2-10426IA                 TE2-06718                   800059
TF2-10426IA                 RP-TR23                     800059
TF2-10426IA                 RP-TR23                     800059
TF2-10426IA                 RP-TR23                     800059
TF2-10426IA                 RP-TR23                     800059
TF2-10426IA                 RP-BX35                     800059
TF2-10426IA                 RP-BX35                     800059
TF2-10426IA                 RP-BX35                     800059
TF2-10426IA                 RP-BX35                     800059

(Sorry apparently a complete n00b today, aside from creating an HTML table, couldn't figure out how to get this to format into a table)

    SELECT WO, TF, TE, CAP, LABEL
    FROM (SELECT DISTINCT Sched.dbo.TBS.WADOCO AS WO,
    Sched.dbo.TBS.WALITM AS TF,
    CASE WHEN Part.IXLITM LIKE 'TE%' THEN Part.IXLITM END AS TE,
    CASE WHEN Part.IXLITM LIKE 'CF%' THEN Part.IXLITM END AS CAP,
    CASE WHEN Part.IXLITM LIKE 'LBL%' THEN Part.IXLITM END AS LABEL
    FROM WB.dbo.Part
    INNER JOIN Sched.dbo.TBS ON TBS.WAAITM=Part.IXKITA) AS T2
    WHERE WO=800059

Which Yields:

WO          TF            TE          CAP            LABEL
800059      TF2-10426IA   NULL        NULL           NULL
800059      TF2-10426IA   NULL        CF-S1094P-UL   NULL
800059      TF2-10426IA   TE2-06718   NULL           NULL

I've made a couple of other attempts at getting everything combined in one line but haven't had any luck yet I think something similar to 'Group By' would be ideal...

The second part of this query that also has me a little stumped, although admittedly I've worked on the above more, is that I need to pull even more data out of the IXLITM column Where IXKITA=[The TE2***] for the TF2*** Number.

I think between the two issues I may look for a solution outside of T-SQL, but figured I'd ask for some insight from all you experts first.

Thanks in advance and any help is greatly appreciated!

4

2 に答える 2

2

これを試して:

SELECT WO, 
       TF, 
       TE, 
       CAP, 
       LABEL 
FROM   (SELECT DISTINCT WADOCO   AS WO, 
                        WALITM   AS TF, 
                        Max(CASE 
                              WHEN IXLITM LIKE 'TE%' THEN PART.IXLITM 
                              ELSE '' 
                            END) AS TE, 
                        Max(CASE 
                              WHEN IXLITM LIKE 'CF%' THEN PART.IXLITM 
                              ELSE '' 
                            END) AS CAP, 
                        Max(CASE 
                              WHEN IXLITM LIKE 'LBL%' THEN PART.IXLITM 
                              ELSE '' 
                            END) AS LABEL 
        FROM   PART 
        GROUP  BY WALITM, 
                  WADOCO)T2 
WHERE  WO = 800059 

SQLFiddleには実用的なソリューションがあります。

于 2012-10-15T18:07:32.693 に答える
1
SELECT DISTINCT Sched.dbo.TBS.WADOCO AS WO,
Sched.dbo.TBS.WALITM AS TF,
TE.IXLITM AS TE,
CF.IXLITM AS CAP,
LBL.IXLITM AS LABEL
FROM Sched.dbo.TBS
LEFT JOIN WB.dbo.Part TE ON TBS.WAAITM = Part.IXKITA AND LEFT(Part.IXLITM,2) = 'TE'
LEFT JOIN WB.dbo.Part CF ON TBS.WAAITM = Part.IXKITA AND LEFT(Part.IXLITM,2) = 'CF'
LEFT JOIN WB.dbo.Part LBL ON TBS.WAAITM = Part.IXKITA AND LEFT(Part.IXLITM,3) = 'LBL'
WHERE WO=800059
于 2012-10-15T18:06:04.780 に答える