Trouble with Rounding Columns

  • I am using SQL through an Excel spreadsheet. Problem is, my code is giving me a headache. I have a column that displays the total of completed invites then another that displays the total invites sent. Now there is a third column that would display the % of invites complete, meaning total complete divided by total sent. I am having trouble getting the percentage to show up correctly. Anyone have any ideas on what I can do?

  • Can you post the formula you are using at the moment and tell us the rounding you are trying to achieve?

    Facts are stubborn things, but statistics are more pliable - Mark Twain
    Carolyn
    SQLServerSpecialists[/url]

  • case (Select Count(*) from ECSQ1Production..contact where (Nominatedforsurvey='true' and TPAccountID=Contact_InterimDbAccountId and NominatedforSurvey='true' and contactsurveystatus='complete'))

    when '0' then '0'

    else

    (Select convert(numeric(5,2),Count(*)) from ECSQ1Production..contact where (Nominatedforsurvey='true' and TPAccountID=Contact_InterimDbAccountId and NominatedforSurvey='true' and contactsurveystatus='complete'))/(Select convert(numeric(5,2),Count(*)) from ECSQ1Production..contact where (InitialEmailInviteDate is not null and TPAccountID=Contact_InterimDbAccountId and NominatedforSurvey='true'))

    end as [% Complete],

  • Problem:

    SELECT 1/10

    Solution:

    SELECT 1/10.0

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (9/18/2008)


    Problem:

    SELECT 1/10

    Solution:

    SELECT 1/10.0

    Many newbies are not beware of implicit convertions 🙂

    http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx


    Madhivanan

    Failing to plan is Planning to fail

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

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