I have query make pivot table based on max feature of value
i need to replace max(featurevalue) with Feature Value
meaning i dont need using aggregate function on pivot .
i need using Feature value it self
when using no aggregate as above it give me error
incorrect syntax near for
how to solve this issue please
What I have tried:
DECLARE @Columns as VARCHAR(MAX)
SELECT @Columns =
COALESCE(@Columns + ', ','') + QUOTENAME(FeatureName)
FROM
(select distinct FT.FeatureName from #ItemFeatures Feat inner join [CustomerLocations].[ItemFeatures] ItemF
on ItemF.CustomerId=Feat.CustomerId INNER join CustomerLocations.FeatureTypes FT on ItemF.FeatureId=FT.FeatureId
) AS B
ORDER BY B.FeatureName
DECLARE @SQLs as VARCHAR(MAX)
SET @SQLs = 'SELECT ItemCode, IPN,PartnerName,CustomerName,FeatureValues ' + @Columns + '
FROM
(
select F.ItemId,F.ItemId as ItemCode,I.IPN,I.PartnerName,I.PartnerPart,Itm.CustomerName,t.FeatureName,F.FeatureValue,F.FeatureValue as FeatureValues
from #ItemFeatures Itm
inner join [CustomerLocations].[ItemFeatures] F on F.CustomerId=Itm.CustomerId
inner join [CustomerLocations].[Items] I on I.ItemID=F.ItemId
inner join CustomerLocations.FeatureTypes T on T.FeatureId=F.FeatureId
) as PivotData
PIVOT
(
FeatureValue
FOR FeatureName IN (' + @Columns + ')
) AS PivotResult
ORDER BY CustomerName'
EXEC(@SQLs)