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

行转列后结果集生成新表的有关问题

2012-06-20 
行转列后结果集生成新表的问题.SQL codeif object_id(dest1) is notnulldrop table dest1declare @yf1 v

行转列后结果集生成新表的问题.

SQL code
if object_id('dest1') is not  null    drop table dest1declare @yf1 varchar(7)declare @yf2 varchar(7)declare @yf3 varchar(7)declare @sqlstr Nvarchar(4000)set @yf1='2012-07'set @yf2='2012-08'set @yf3='2012-09'set @sqlstr='select *  into dest1 from (select 部品品番,供应商名称,sum(case 月份 when '''+ @yf1 + '''then 部品数量 else 0 end) '''+  @yf1 +'''           ,sum(case 月份 when '''+ @yf2 + '''then 部品数量 else 0 end) '''+  @yf2 +'''            ,sum(case 月份 when '''+ @yf3 + '''then 部品数量 else 0 end) '''+  @yf3 +'''           from dest group by 部品品番,供应商名称)'select @sqlstrexec(@sqlstr)/*-----------------------------if object_id('dest1') is not  null    drop table dest1declare @yf1 varchar(7)-----------------------------*/(所影响的行数为 1 行)服务器: 消息 170,级别 15,状态 1,行 4第 4 行: ')' 附近有语法错误。


[解决办法]
望给出测试数据
[解决办法]
需要给子查询一个表别名。

热点排行