SQL Server stored procedure percentage formula

Posted on 2007-07-30
Last Modified: 2007-07-30
How do I create a percentage as a formula in a stored procedure.  Currently my data is as follows

Field 1 - 960
Field 2 - 636
Field 3 - Field 2 / (Field 1 + Field 2) - answer should be .398 but is coming back with 0

Syntax from the stored procedure Select Statement for the percentage field is

(fEmployeeTracking_Actions.Field1) / (fEmployeeTracking_Actions.Field1 + fEmployeeTracking_Actions.Field2)

Question by:softdimensions
    LVL 142

    Accepted Solution

    cast(fEmployeeTracking_Actions.Field1 as decimal(10,4)) / cast(fEmployeeTracking_Actions.Field1 + fEmployeeTracking_Actions.Field2 as decimal(10,4))

    Author Comment

    Thanks - works perfect

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
    Via a live example, show how to shrink a transaction log file down to a reasonable size.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

    728 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

    15 Experts available now in Live!

    Get 1:1 Help Now