/*
表里3条记录片段:
SORDER   EDA      BUN      CUST     NOUBA     JITU0    APRICE
RR128254 0 1 CSZ003U CSZ004U 62.700 62.10000000
RR128254 0 2 CSZ003U CSZ004U 213.750 62.10000000
RR128254 0 3 CSZ003U CSZ004U 8.550 62.10000000
*/
select case when cust='chf001j'and nouba='chf001j' then ceiling(jitu0*aprice)
       when right(cust,1)='j'and cust<>'chf001j'and nouba<>'chf001j'then round(jitu0*aprice,0)
       else round(jitu0*aprice,2) end
from xract where sorder='RR128254'--照理应出来 round(jitu0*aprice,2)的结果,但是却出来ceiling(jitu0*aprice)的结果,怎么回事?

解决方案 »

  1.   

    为了正确说明你得到的结果,将then 后都用字符串试试比如 then 'a' then 'b' else 'c'
      

  2.   

    你可以这样测试,就知道它读取的是哪个值select case when cust='chf001j'and nouba='chf001j' then 'a'  when right(cust,1)='j'and cust<>'chf001j'and nouba<>'chf001j'then 'b'
      else 'c' end
    from xract where sorder='RR128254'
    出来应该是c
      

  3.   

    select 
    case when cust='chf001j'and nouba='chf001j' then 'a'
    when right(cust,1)='j'and cust<>'chf001j'and nouba<>'chf001j'then 'b'
    else 'c' end,
    * from xract where sorder='RR128254'出来是c但用
    select case when cust='chf001j'and nouba='chf001j' then ceiling(jitu0*aprice)
    when right(cust,1)='j'and cust<>'chf001j'and nouba<>'chf001j'then round(jitu0*aprice,0)
    else round(jitu0*aprice,2) end
    from xract where sorder='RR128254'
    出来就是
    3894
    13274
    531
      

  4.   

    Microsoft SQL Server 2005 - 9.00.3042.00 (Intel X86)   Feb  9 2007 22:47:07   Copyright (c) 1988-2005 Microsoft Corporation  Standard Edition on Windows NT 6.0 (Build 6002: Service Pack 2) 
      

  5.   

    各位老大帮忙啊,急,这是否是Microsoft 的BUG啊?
      

  6.   

    别用ROUND函数截取,用DEC 或 NUMERIC来,上次忘了有讨论过ROUND函数关于版本的不同,
      

  7.   

    你的结果要输出成一个字段,由于前两种结果都会使这个字段是个整型的,造成第三种结果保存成整型的了。
    你试试:select case 
      when cust='chf001j'and nouba='chf001j' then cast(ceiling(jitu0*aprice) as numeric(10,2))
      when right(cust,1)='j'and cust<>'chf001j'and nouba<>'chf001j'then cast(round(jitu0*aprice,0) as numeric(10,2))
      else cast(round(jitu0*aprice,2) as numeric(10,2)) end
    from xract where sorder='RR128254'
      

  8.   

    不信你看print case when 1<>1 then  round(100.00,2) else ceiling(200) end
    print ceiling(200)
    /*
    200.00
    200
    */同样是打印ceiling(200),但第一种情况,它会根据CASE转成了非整型了
      

  9.   

    原因知道了,确实如rmljoe所说那样。我已强制转换成decimal(28,2)!