Change in Query

  • I'm guessing it's due to the underlying columns being of INT datatype

    SELECTServerName = @@SERVERNAME,

    TotalSpaceMB = SUM(CA1.total_bytes),

    AvailableSpaceMB = SUM(CA1.available_bytes),

    --Integer Maths will return 0

    SUM(CA1.available_bytes) / SUM(CA1.total_bytes),

    --Decimal

    SUM(0E + CA1.available_bytes) / SUM(0E + CA1.total_bytes),

    SUM(0E + CA1.available_bytes) / SUM(0E + CA1.total_bytes) * 100

    FROMmaster.sys.master_files AS MF

    CROSSAPPLYmaster.sys.dm_os_volume_stats(MF.database_id, MF.file_id) AS CA1;

  • See the difference

    DECLARE

    @total INT = 5

    ,@free INT = 4

    SELECT @free/@total*100 AS INTEGER_ARITHM

    , (0.+@free)/@total*100 AS NUMERIC_ARITHM

    You also may convert it explicitly using exactly precsion you need.

  • Thank you Very Much. It worked.

    Sagar Sonawane
    ** Every DBA has his day!!:cool:

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

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