我正在尝试做一个相当符号枢轴。这个按预期运行:
with cte as
(
select Symbol, TradeDate, 'Per' + cast(Period as CHAR(3)) Per, Value
from tblDailySMA
)
select * from cte
pivot
(Max(Value) for Per in (Per5,Per10,Per15,Per20,Per30,Per40,Per50,Per60,Per80,Per100,Per110,Per120,
Per150,Per200)) pvt
这个给出了错误Incorrect syntax near 5
(并突出显示了“for Period in”之后的第一个值(5):
with cte as
(
select Symbol, TradeDate, Period, Value
from tblDailySMA
)
select * from cte
pivot
(Max(Value) for Period in (5,10,15,20,30,40,50,60,80,100,110,120,150,200)) pvt
经过多次试验和错误后,我得到了第一个运行...是否有原因,例如可能不允许整数值作为列名?谢谢..