I am trying to build a list of Care Instructions that are in use by products in GroupCode 104, but can't get my head around merging these two queries? Or is there a better way?
Query1
SELECT A.[Code], T1.ProductCode,
Split.a.value('.', 'VARCHAR(100)') AS String
FROM (SELECT [Code],
CAST ('
FROM Table2 A) AS A CROSS APPLY String.nodes ('/M') AS Split(a)
INNER JOIN Table1 T1 ON [Code]=T1.[ProductCode]
WHERE T1.GroupCode='104'
Query 2
SELECT * FROM Table3
Table1 | |
ProductCode | GroupCode |
A1 | 104 |
A2 | 104 |
A3 | 104 |
B1 | 104 |
B2 | 104 |
B3 | 104 |
C1 | 114 |
Table2 | |
Code | Care |
A1 | DNB,DND,DNT,IMH |
A2 | DNB,DND,DNT,IMH |
A3 | DNB,DND,DNT,IMH |
B1 | DNB, SO |
B2 | DNB, SO |
B3 | DNB, SO |
C1 | MW30, DNT |
Table3 | |
Care | Details |
DNB | Do not bleach |
DNT | Do not tumble dry |
ILH | Iron - Low... |