Management Studio报告:关键字“ for”附近的语法不正确。PlType以两种类型的名称开头,即:2或4。示例:20H,20D,20M,40H,40D,40M,40X等是不同类型的PlType
Select *
Into #PivotTbl from
(Select Country, PlType , LEFT(PLTYPE,1) as PType
From #ToPivot ) As ToPvt
Pivot
(PlType for PType in (2,4)) As Piv1
我不明白“ for”附近的错误是什么。当我更换
(PlType for PType in (2,4)) As Piv1
和
(max(PlType) for PType in (2,4)) As Piv1
我收到错误:“ 2”附近的语法不正确。请帮助我解决此问题。
2和4成为枢轴中的列,您需要将它们用方括号括起来,如下所示:
Select *
Into #PivotTbl from
(Select Country, PlType , LEFT(PLTYPE,1) as PType
From #ToPivot ) As ToPvt
Pivot
(max(PlType) for PType in ([2],[4])) As Piv1
即使您不使用,也会收到此错误max
。原因是您必须将聚合函数与一起使用pivot
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句