SQL Server Management Studio is automatically rounding my calculation

Posted on 2011-04-28
Last Modified: 2012-05-11
Hi !

SQL Server Management Studio is automatically rounding my calculation done in TSQL in the result pane. How can I avoid this.

Thank You !
Question by:Rubicon2009
    LVL 38

    Expert Comment

    by:Aaron Tomosky
    You can
    Select cast(field as decimal(18,2)) from table

    If you give us your query and sample data we can give more specific help.

    Author Comment

    SELECT (A.ActualEnd - A.ActualStart - Isnull(A.Lunch, 0)) / 60 AS 'FinalDuration'

    with real values, the result will be 7 instead of 7,25
    SELECT (780 - 300 - 45) / 60

    FYI, values are minutes from midnight
    LVL 69

    Accepted Solution

    because you divide by an integer:

    SELECT (780 - 300 - 45) / cast(60 as money)

    Author Comment

    Using CAST like suggested is still giving me the wrong results, I now optain 7.00 instead of 7.25

    Author Comment

    (780 - 300 - 45) / 60.0
    Is resulting 7.25000


    Author Closing Comment

    Thank You

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
    How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Via a live example, show how to shrink a transaction log file down to a reasonable size.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now