Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Merge two select statements in SQL 2014

$
0
0

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 ('' + REPLACE(Table2.[Care], ',', '') + '' AS XML) AS String
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
ProductCodeGroupCode
A1104
A2104
A3104
B1104
B2104
B3104
C1114

Table2
CodeCare
A1DNB,DND,DNT,IMH
A2DNB,DND,DNT,IMH
A3DNB,DND,DNT,IMH
B1DNB, SO
B2DNB, SO
B3DNB, SO
C1MW30, DNT

Table3
CareDetails
DNBDo not bleach
DNTDo not tumble dry
ILHIron - Low...

Viewing all articles
Browse latest Browse all 4871

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>