TEL:150-0382-3679
新闻资讯 News Center
建站知识 / 公司动态
产品动态属性行转列

DECLARE @columns NVARCHAR(MAX), @sql NVARCHAR(MAX);

-- 获取不重复的AttributeName列表

SELECT @columns =

STUFF((SELECT DISTINCT ',' + QUOTENAME(attriname)

FROM ProClass_Attri

FOR XML PATH(''), TYPE

).value('.', 'NVARCHAR(MAX)'), 1, 1, '');


-- 构建并执行动态PIVOT查询

SET @sql = '

SELECT classid, ' + @columns + '

FROM (

SELECT classid, attrivalue, attriname

FROM ProClass_Attri

) AS SourceTable

PIVOT (

MAX(attrivalue)

FOR attriname IN (' + @columns + ')

) AS PivotTable';

EXEC sp_executesql @sql;

一站式全网营销,您身边的网络营销顾问,为您一对一私人定制符合您实际需求的网络营销实施方案!
24小时咨询热线:
150-0382-3679