首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

行转列。Value值替String类型,如果合并

2012-07-30 
行转列。Value值为String类型,如果合并SQL codeselect distinct tp.[order],tp.Module,(case tpt.Name when

行转列。Value值为String类型,如果合并

SQL code
select distinct tp.[order],tp.Module,(case tpt.Name when 'Color' then Value else '' end) Color,(case tpt.Name when 'Total' then Value else '' end) Total,(case tpt.Name when 'DeliveryDate' then Value else '' end) DeliveryDate from UserDataModel.T_LeanLinePlan tp left joinUserDataModel.T_LeanLinePlanAttribute tpton tp.LeanLinePlanId=tpt.LeanLinePlanId


value值为‘’,所有数据集出现很多空白的

[解决办法]
SQL code
select tp.[order],tp.Module,Max(case tpt.Name when 'Color' then Value else '' end) Color,Max(case tpt.Name when 'Total' then Value else '' end) Total,Max(case tpt.Name when 'DeliveryDate' then Value else '' end) DeliveryDate from UserDataModel.T_LeanLinePlan tp left joinUserDataModel.T_LeanLinePlanAttribute tpton tp.LeanLinePlanId=tpt.LeanLinePlanIdWhere Name in('Color','Total','DeliveryDate')Group by tp.[order],tp.Module 

热点排行