Solved

calculated percentage data always retruning zero

Posted on 2006-07-13
2
344 Views
Last Modified: 2008-03-17
I'm trying to use T-SQL to return the relative percentage of two summed values when I divide the values into each other, but I always get 0. Here is my stored proc
CREATE PROCEDURE dbo.SC_PMPULL

(
      @startdate datetime,
      @enddate datetime
)
AS
BEGIN

SELECT underwrtr,COUNT (received)as received,count(denied)as denied,fullname
 
INTO #tmpPull
FROM dbo.TestPull
WHERE received BETWEEN @startDate and @enddate and received is not null
GROUP BY underwrtr,fullname, denied,received
Select P.fullname, coalesce(sum(P.received), ' ')as [U/W Received],coalesce(sum (P.denied) ,' ')as [U/W Denied] , P.underwrtr,(sum(P.denied) /sum(P.received) )as PercentageDenied--,P.month,P.year,P.monthvol
   From #tmpPull  P
     Group by P.fullname,P.underwrtr
drop table #tmpPull


END

0
Comment
Question by:jemigossaye
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Assisted Solution

by:pootle_flump
pootle_flump earned 200 total points
ID: 17103481
Hi

Your values are Ints - you need to cast them as DECIMAL (or NUMERIC) e.g.:

CAST((sum(P.denied) AS NUMERIC, 4, 3) /sum(P.received) )as PercentageDenied


0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 17103486
CREATE PROCEDURE dbo.SC_PMPULL

(
     @startdate datetime,
     @enddate datetime
)
AS
BEGIN

SELECT underwrtr,COUNT (received)as received,count(denied)as denied,fullname
 
INTO #tmpPull
FROM dbo.TestPull
WHERE received BETWEEN @startDate and @enddate and received is not null
GROUP BY underwrtr,fullname, denied,received
Select P.fullname, coalesce(sum(P.received), ' ')as [U/W Received],coalesce(sum (P.denied) ,' ')as [U/W Denied] , P.underwrtr,(cast(sum(P.denied)  as decimal(20,4)) / cast(sum(P.received)  as decimal(20,4)) )as PercentageDenied--,P.month,P.year,P.monthvol
   From #tmpPull  P
     Group by P.fullname,P.underwrtr
drop table #tmpPull
0

Featured Post

Upcoming Webinar: Percona XtraDB Cluster 6/21 10am

Join Percona’s MySQL Practice Manager Kenny Gryp and QA Engineer, Ramesh Sivaraman as they present Percona XtraDB Cluster, Galera Cluster, MySQL Group Replication on Wednesday, June 21, 2017 at 10:00 am PDT / 1:00 pm EDT (UTC-7).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

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