现有如下表格
Table:rsi_attributes 主表
attributeCode attributeName
1 name
2 description
3 brand
4 upc
5 itemNumber
6 storeNumber
7 itemDescription Table: rsi_masterdata 从表
reference attributeCode attributeValue
1 1 GTIN 1
1 2 Global Trade Item Number1
1 3 HP laptop
1 4 4002533276811
1 5 12564439
2 1 GTIN 2
2 2 Global Trade Item Number2
2 3 HP Printer
2 4 4002533276812
主表与从表之间通过attributeCode相互关联
先要求查询结果如下:
reference name description brand upc itemnumber
1 GTIN 1 Global Trade Item Number1 HP 4002533276811 12564439
2 GTIN 2 Global Trade Item Number2 HP Printer 4002533276812
请各位高数,帮忙一起解决一下,由于小弟可用积分较少,只能意思一下
Table:rsi_attributes 主表
attributeCode attributeName
1 name
2 description
3 brand
4 upc
5 itemNumber
6 storeNumber
7 itemDescription Table: rsi_masterdata 从表
reference attributeCode attributeValue
1 1 GTIN 1
1 2 Global Trade Item Number1
1 3 HP laptop
1 4 4002533276811
1 5 12564439
2 1 GTIN 2
2 2 Global Trade Item Number2
2 3 HP Printer
2 4 4002533276812
主表与从表之间通过attributeCode相互关联
先要求查询结果如下:
reference name description brand upc itemnumber
1 GTIN 1 Global Trade Item Number1 HP 4002533276811 12564439
2 GTIN 2 Global Trade Item Number2 HP Printer 4002533276812
请各位高数,帮忙一起解决一下,由于小弟可用积分较少,只能意思一下
解决方案 »
- mssql2005 日志收缩问题
- 我在使用Proxool 0.9.0RC2做数据库连接池得时候,出现得问题,不知道在那么解决
- 2个表递归查询到一个新表中,学习
- 超难问题!!!! 如何用 t-sql 语句 获得 有 多少个 客户端 连接 数据库 !!!!!!!!!!!!!
- SQL 按ID及列内容自动生成序号排序问题
- 请问事件探察器的作用是什么?一般怎样使用?
- 如何在query中用一个变量来接收触发器中的返回值?
- 刚才只顾高兴了,一下把帖子结了,你们还没推荐我几本SQLSERVER7的好书呢,要电子版的,给个连接
- 100分求助:数据库中某表某记录发生了增、删、改后,如何实时捕获?
- 这样的SQL能否实现?【姐妹题】
- SQL 合并行 探寻更简明方法
- sql~帐目汇总`~`急~~高手来~999999999 全部家当 40分 不好意思啊
declare @isnullName varchar(2000)select @columnName = isnull(@columnName+',','') +'['+ attributeName + ']',
@isnullName = isnull(@isnullName+',','') + 'isnull(' + attributeName + ','''') as '+attributeName+''
from dbo.rsi_attributes
where attributecode in (select attributecode from dbo.rsi_masterdata)declare @sql nvarchar(1000)
set @sql = 'select reference,' + @isnullname +
' from
(
select b.reference,a.attributename ,b.attributevalue
from dbo.rsi_attributes a , dbo.rsi_masterdata b
where a.attributecode = b.attributecode ) a
pivot (max(attributevalue) for attributename in (' + @columnname + ')) as pvt'exec sp_executesql @sql