Home > Database > Mysql Tutorial > body text

自定义属性应用-自定义属性行转列

WBOY
Release: 2016-06-07 16:06:34
Original
1219 people have browsed it

通过sql case when对商品表自定义属性进行查询,实现行专列效果。 declare @sql varchar(8000)set @sql=select StyleNoselect @sql=@sql+,+[A_GoodsAttr].AttrName+=isnull(max(case AttrName when +[A_GoodsAttr].AttrName+ then AttrValue end),0) from A_

通过sql case when对商品表自定义属性进行查询,实现行专列效果。

declare @sql varchar(8000)

set @sql='select StyleNo'

select @sql=@sql+','+[A_GoodsAttr].AttrName+'=isnull(max(case AttrName when '''+[A_GoodsAttr].AttrName+''' then AttrValue end),0)'

 from A_GoodsAttr order by AttrId 

set @sql=@sql+' from A_ProAttrList where  1=1 and StyleNo=''100010'' group by StyleNo order by StyleNo'

print @sql

exec(@sql)
Copy after login

1、全部商品自定义属性
\

2、单货号自定义属性
\

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!