Home  >  Article  >  Database  >  自定义属性应用-自定义属性行转列

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

WBOY
WBOYOriginal
2016-06-07 16:06:341203browse

通过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)

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

2、单货号自定义属性
\

Statement:
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