Hi Lynn, thanks for the reply
The value in ParentFeatureName can be dynamically change..it will not always give the same value
I am trying this dynamic pivot..but still not getting the desire results
there is error
DECLARE @ParentFeatureName varchar(max)
SELECT @ParentFeatureName = STUFF((select distinct ',['+'ParentFeatureName'+']' from #Test for xml path(' ')),1,1,'')
--error is coming here to get the distict value
SELECT @ParentFeatureName = (
SELECT SUBSTRING(
(SELECT DISTINCT ',' + CAST(ParentFeatureName as Varchar(MAX)) FROM #Test FOR XML PATH('')),2,2000000))
SELECT
ProductID,'+@ParentFeatureName+'
FROM
(SELECT * FROM #Test) AS D
PIVOT
(
MIN(MasterFeatureValue)
FOR ParentFeatureName IN ('+@ParentFeatureName+')
) AS DD
Group By ProductID
DECLARE @sql VARCHAR(max)
SET @sql = '
SELECT
ProductID,'+@ParentFeatureName+'
FROM
(SELECT * FROM #Test) AS D
PIVOT
(
MIN(MasterFeatureValue)
FOR ParentFeatureName IN ('+@ParentFeatureName+')
) AS DD
Group By ProductID'
EXEC @sql