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

邹老大书上的一个行列转置,如何不对

2012-01-10 
邹老大书上的一个行列转置,怎么不对?createtable#tb(Yearint,Quarint,Pricedecimal(10,2))insert#tbselect

邹老大书上的一个行列转置,怎么不对?
create   table   #tb(
Year   int,
Quar   int,
Price   decimal(10,2))

insert   #tb   select   2001,1,2.1
union   all   select   2001,2,1.7
union   all   select   2001,3,1.6
union   all   select   2002,1,2.7
union   all   select   2002,2,3.1
union   all   select   2002,3,2.4
union   all   select   2003,1,1.9
union   all   select   2003,2,1.3

declare   @s   varchar(8000)
set   @s= 'select   Year '
set   @s=@s
        + ',(case   Quar   when '+cast(Quar   as   varchar)+ 'then   price   end)   as   '+cast(Quar   as   varchar)
        + '   from   #tb '

SQL是我自己写的,不是邹老大的;
提示:列名   'Quar '   无效。

请问哪错了,为什么?

[解决办法]
最後的+ ' from #tb '

改成 from #tb

热点排行
Bad Request.