当前位置: 代码迷 >> Sql Server >> 邹老大书上的一个行列转置,如何不对
  详细解决方案

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

热度:0   发布时间:2016-04-27 20:17:36.0
邹老大书上的一个行列转置,怎么不对?
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   @[email protected]
        + ',(case   Quar   when '+cast(Quar   as   varchar)+ 'then   price   end)   as   '+cast(Quar   as   varchar)
        + '   from   #tb '

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

请问哪错了,为什么?

------解决方案--------------------
最後的+ ' from #tb '

改成 from #tb
  相关解决方案