locked
case when function return different decimal places RRS feed

  • Question

  • User-804681621 posted
    I can't use 'case when' to return different format as below sql.

    Select case when ccy='hkd' then cast(price as decimal(18,2)) else round(price,0) from table.

    How to solve it?
    Friday, February 26, 2016 3:19 AM

All replies

  • User-1716253493 posted

    Hi pn_nq,

    formated number is varchar type

    case when ... then varchar1 else varchar2 end

    Friday, February 26, 2016 3:46 AM
  • User-804681621 posted
    Can I finally format to float data type?
    I try to format float for float1 and float2, but fail

    How to fix
    Friday, February 26, 2016 6:30 AM
  • User364663285 posted

    Can I finally format to float data type?
    I try to format float for float1 and float2, but fail

    How to fix

    Try

    Select case when ccy='hkd' then cast(price as decimal(18,2)) else cast(price as decimal(18,0)) from table

    Tuesday, March 1, 2016 5:00 AM