return 2 digits from sql statement with a divide in it

Posted on 2007-10-03
Last Modified: 2008-01-09
Sql statment:
select Sum((ialrtartot-ialrtvptot)/(ialrtartot)) as Yield from table.

I only want 2 digits returned for yield, i.e. .26.

Question by:bergertime
    LVL 11

    Accepted Solution

    Does this work?

    select CAST(Sum((ialrtartot-ialrtvptot)/(ialrtartot)) AS decimal(10,2)) as Yield from table
    LVL 16

    Expert Comment

    select ROUND(Sum((ialrtartot-ialrtvptot)/(ialrtartot)),2) as Yield from table
    LVL 2

    Author Comment

    cmhunty, it works but rounds down, sql server dba it rounds up but does not cut off the digits, as I get .29000000.  Since it does not have to be rounded up it will work for me,  thanks to both of you.
    LVL 11

    Expert Comment

    Guess you could do both!

    select CAST(ROUND(Sum((ialrtartot-ialrtvptot)/(ialrtartot)),2) AS decimal(10,2)) as Yield from table

    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

    Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

    729 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

    19 Experts available now in Live!

    Get 1:1 Help Now