Hi,@ahmed salah
Welcome to Microsoft T-SQL Q&A Forum!
Please try the following code:
;with cte as
(
SELECT P.PartId,
STUFF((SELECT ' | ' + [FeatureName] + '( '+ [FeatureValue] + ' )'
FROM #partsfeature A
WHERE A.PartId=P.PartId
Order by featureName
FOR XML PATH('')),1,2,'') AS FeaturesValueCollection
FROM #partsfeature P
GROUP BY P.PartId
)
select c.PartId,p.FeatureName ,p.FeatureValue ,FeaturesValueCollection FROM CTE c
inner join #partsfeature p on p.PartId=c.PartId
Best regards,
Bert Zhou
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.