JackQu的程序员博客

欢迎来的我Blog.这里记录工作学习的点滴,愿与大家分享。欢迎大家共同交流 。

导航

SQL-使用Case进行行列转换


select sum(case FcyNo when 'USD' then fcyamt else 0 end) usd from accbillsitems
提示错误 expression evaluation 
not supported

改成 
select case FcyNo when 'USD' then fcyamt else 0 end usd from accbillsitems
依旧提示 expression evaluation 
not supported (不是Amt 引起的错误)

改成 
select case FcyNo when 'USD' then fcyamt else 0.0 end usd from accbillsitems
没有错误提示可以检索出数据 (
else 后的数据类型要和前面的 Fcyamt的数据的类型一样)

改成 
select sum(case FcyNo when 'USD' then fcyamt else 0.0 end)usd from accbillsitems
提示错误 data type 
not supported for arithmetic (不能进行Sum运算)

改成 
select Sum(Case FcyNo WHEN 'USD' THEN FCYAMT else cast(0.0 as DOUBLE PRECISIONEND) usd from accbillsitems

posted on 2008-12-19 15:43  Qcj  阅读(354)  评论(0编辑  收藏  举报