Divide two columns in different tables

  • Hi all

    I need help with writing a SQLstatement for an Arithmetic expression (Division) by joining two tables.

    How can I get % Score as a Calculated Field?

    Say for example 1st row in the screenshot is 15/183 = 0.0819. I need to see (100-(15/183*100)) = 91.80 which would the the Percentage of the two fields for a person.

    SELECT *

    FROM [dbo].[Calls_OutsideSLA] OS

    INNER JOIN [dbo].[Calls_InsideSLA] INS ON ( OS.Person= INS.Person) 

    Attachments:
    You must be logged in to view attached files.
  • It's really quite straightforward

    Where X and Y are the two values from your results (OS.RecordCount and INS.RecordCount respectively ) use the following formula (a simplified version of your own):

    (y-x/y)*100

    In your SELECT statement eg.

    SELECT 100.0 * (Y-X)/Y 
    FROM ...<your results>...

    As it looks like your RecordCounts are integers you must ensure you cast your values to a decimal value (with appropriate precision and scale) or you will see just zeroes (probably) in your results. See CAST and DECIMAL in the docs

Viewing 2 posts - 1 through 1 (of 1 total)

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