Here's the TABLE Definitions, INSERT Statements, and Expected Results:
NOTE: These tables originate from a PROGRESS database that are accessible from a linked server utilizing the OPENQUERY function, so it appears that there are no identity fields.
*** CREATE ***
CREATE TABLE dbo.WOAudit(
WONumber varchar(26) NULL,
MachPCode varchar(50) NULL,
MachSCode varchar(100) NULL
)
CREATE TABLE pub.MachinePCodes(
MachPCode varchar(6) NULL,
Description varchar(100) NULL
)
CREATE TABLE pub.MachineSCodes(
MachSCode varchar(6) NULL,
MachPCode varchar(6) NULL,
Description varchar(100) NULL
)
*** INSERT ***
INSERT INTO pub.MachinePCodes
VALUES('21','Quality'),
('33','Wrapping')
INSERT INTO pub.MachineSCodes
VALUES('21','330','Other'),
('21','306','Bad Bond'),
('33','306','Cold Wrap'),
('33','330','Warm Wrap')
INSERT INTO pub.WOAudit
VALUES('70412053600','21','330'),
('70412053601','33','306'),
('70412053602','33','306,330'),
('70412053603','33','330')
*** Expected Results ***
WONumber MachPCode PDesc MachSCode SDesc
70412053600 21 Quality 330 Other
70412053601 33 Wrapping 306 Bad Bond
70412053602 33 Wrapping 306,330 Cold Wrap, Warm Wrap
70412053603 33 Wrapping 330 Warm Wrap