sql语句行转列语句报错
金蝶云社区-云社区用户G9Ov1234
云社区用户G9Ov1234
0人赞赏了该文章 1,655次浏览 未经作者许可,禁止转载编辑于2014年02月20日 11:18:29

谁帮我看看我写了一个sql语句,看看有什么错误,想实现行转列
select sum(case a.fperiod when 1 then b.famount end)as 1月份,sum(case a.fperiod when 2 then b.famount end)as 2月份,sum(case a.fperiod when 3 then b.famount end)as 3月份,sum(case a.fperiod when 4 then b.famount end)as 4月份,sum(case a.fperiod when 5 then b.famount end)as 5月份,sum(case a.fperiod when 6 then b.famount end)as 6月份,sum(case a.fperiod when 7 then b.famount end)as 7月份,sum(case a.fperiod when 8 then b.famount end)as 8月份,sum(case a.fperiod when 9 then b.famount end)as 9月份,sum(case a.fperiod when 10 then b.famount end)as 10月份,sum(case a.fperiod when 11 then b.famount end)as 11月份,sum(case a.fperiod when 12 then b.famount end)as 12月份 from T_IM_SALEISSUEBILL as a left outer join T_IM_SaleIssueEntry as b on b.FPARENTID=a.FID left outer join T_BD_Material as c on b.FMATERIALID=c.FID left outer join T_SCM_TransactionType as d on d.fid=a.FTransactionTypeID left outer join T_ORG_Storage as e on e.fid=a.FSTORAGEORGUNITID left outer join T_BD_MATERIALGROUP as f on f.fid=c.FMaterialGroupID where (d.fnumber='254' or d.fnumber='243') and a.fyear=2013 group by a.fyear,a.fperiod order by a.fyear asc,a.fperiod asc


错误详细日志如下:
complete! use time: 0 end time: 2014-02-20 11:20:00translate sql exception, message is
parse error. detail message is :
Error
source sql is :
select sum(case a.fperiod when 1 then b.famount end)as 1月份,sum(case a.fperiod when 2 then b.famount end)as 2月份,sum(case a.fperiod when 3 then b.famount end)as 3月份,sum(case a.fperiod when 4 then b.famount end)as 4月份,sum(case a.fperiod when 5 then b.famount end)as 5月份,sum(case a.fperiod when 6 then b.famount end)as 6月份,sum(case a.fperiod when 7 then b.famount end)as 7月份,sum(case a.fperiod when 8 then b.famount end)as 8月份,sum(case a.fperiod when 9 then b.famount end)as 9月份,sum(case a.fperiod when 10 then b.famount end)as 10月份,sum(case a.fperiod when 11 then b.famount end)as 11月份,sum(case a.fperiod when 12 then b.famount end)as 12月份 from T_IM_SALEISSUEBILL as a left outer join T_IM_SaleIssueEntry as b on b.FPARENTID=a.FID left outer join T_BD_Material as c on b.FMATERIALID=c.FID left outer join T_SCM_TransactionType as d on d.fid=a.FTransactionTypeID left outer join T_ORG_Storage as e on e.fid=a.FSTORAGEORGUNITID left outer join T_BD_MATERIALGROUP as f on f.fid=c.FMaterialGroupID where (d.fnumber='254' or d.fnumber='243') and a.fyear=2013 group by a.fyear,a.fperiod order by a.fyear asc,a.fperiod asc