How to display a numeric value in different formats depending on value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kat Magic
    New Member
    • Dec 2010
    • 1

    #1

    How to display a numeric value in different formats depending on value

    I need to be able to display data in a different decimal format depending on the value of a selected column ("myDecimalData "). Below does not work, every value is displayed in hundredths, and I do not understand why. How would I accomplish this?

    For instance, my data:
    less than 10 --> sample: I want to display 9.00 as 9.00
    between 10 and 1000 --> sample: I want to display 10.11as 10.1
    greater than 1000 --> sample: I want to display 1000.11 as 1000


    Code:
    SELECT
    CASE 
    WHEN myDecimalData > 1000 THEN CONVERT(int, myDecimalData)
    WHEN myDecimalData < 10 THEN CONVERT(DECIMAL(18, 2), myDecimalData)
    WHEN myDecimalData between 10 and 1000 THEN CONVERT(DECIMAL(18, 1), myDecimalData)
    END as NewDecimalData from myTable
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    This would be much better handled in your front-end, not in back-end...

    Good Luck!!!

    ~~ CK

    Comment

    Working...