How to return values who have more than 2 decimal

  • Hello

    I have the following SELECT:

    select sum(edeb) from ml where year(data)=2003

    i know that field EDEB keep always 2 decimals ex: 1234.34 but in some circuntancies they keep more decimals

    How can i build a TSQL statment to return me when i have more than 2 decimals.

    Also in SQL the values on the query pane appears with the "." in the decimal separator, then when i paste the contents to excel i can´t make SUM calculation. How to replace the "." to "," decimal separator.

     

    Many thanks

    Luis Santos

  • What datatype is your edeb column? If it's a float, then you're going to get some rounding errors and no real control on how many decimals the SUM() will produce.

    The notator for decimalpoint in Excel is dependant on your local language settings. I usually just mark the column in Excel and use Edit -> Replace whenever I need to switch between , and .

    /Kenneth

  • Select the column in question in Excel. Right click. Format cells. Choose the formar required.

    SQL way to get the round

    DECLARE @MyNum DECIMAL(10,5)

    SET @MyNum = 12345.67899

    SELECT @MyNum MyNum, CONVERT(DECIMAL(10,2), @MyNum) Converted, ROUND(@MyNum, 2) Rounded

    Regards,
    gova

  • Kenneth is correct about FLOATs.  But if EDEB is DECIMAL, the following WHERE clause should select only those with >2 d.p.'s.

    where year(data)=2003 and round(edeb, 2) <> edeb

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply