Dear Ahmedsa,
Kindly refer below sample query.
SQL
CREATE TABLE #PartsFeature
(
PartId INT,
Featurekey NVARCHAR(200),
FeatureValue NVARCHAR(200),
)
INSERT INTO #PartsFeature(PartId,Featurekey,FeatureValue)
VALUES
(1550,'Botato','Yellow'),
(1550,'Mango','Red'),
(1550,'dates','Black'),
(1600,'Rice','white'),
(1600,'macrona','Red'),
(1600,'chicken','Yellow'),
(1700,'Guava','Yellow'),
(1700,'grapes','Green'),
(1700,'FIG','Red')
SELECT DISTINCT PartId,
STUFF((SELECT '$' + CAST(Featurekey AS VARCHAR(100))
FROM #PartsFeature t2
WHERE t2.PartId = t1.PartId
FOR XML PATH('')),1,1,'') 'Featurekey',
STUFF((SELECT '$' + CAST(FeatureValue AS VARCHAR(100))
FROM #PartsFeature t2
WHERE t2.PartId = t1.PartId
FOR XML PATH('')),1,1,'') 'FeatureValue'
FROM #PartsFeature t1
DROP TABLE #PartsFeature
Output
PartId |
Featurekey |
FeatureValue |
1550 |
Botato$Mango$dates |
Yellow$Red$Black |
1600 |
Rice$macrona$chicken |
white$Red$Yellow |
1700 |
Guava$grapes$FIG |
Yellow$Green$Red |