Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL Percentage calculations

Author  Topic 

hbadministrator
Posting Yak Master

120 Posts

Posted - 2014-02-14 : 11:07:02
I have 3 lines of code that work but it is showing us as multiple decimal places out. I need it to stop after 2.


Code 1
dbo.HB_JL_JobCost.TotalTD / dbo.HB_JL_JobCost.EstimateCost * 100 * dbo.job.[sched-value] AS Earned


Code 2
(dbo.job.[sched-value] - dbo.HB_JL_JobCost.EstimateCost)
/ dbo.job.[sched-value] * 100 AS GPper


Code 3
dbo.HB_JL_JobCost.TotalTD / dbo.HB_JL_JobCost.EstimateCost * 100 AS PerCom



Code 3

dbo.HB_JL_JobCost.TotalTD / dbo.HB_JL_JobCost.EstimateCost * 100 AS PerCom

hbadministrator
Posting Yak Master

120 Posts

Posted - 2014-02-14 : 11:48:05
Got my answers

CAST(ROUND((dbo.job.[sched-value] - dbo.HB_JL_JobCost.EstimateCost)/ dbo.job.[sched-value] * 100, 2) AS Numeric(16, 2)) AS GPper
CAST(ROUND(dbo.HB_JL_JobCost.TotalTD / dbo.HB_JL_JobCost.EstimateCost * 100, 2) AS Numeric(16,2)) AS PerCom
CAST(ROUND(dbo.HB_JL_JobCost.TotalTD / dbo.HB_JL_JobCost.EstimateCost * 100, 2) * dbo.job.[sched-value] AS Numeric(16, 2)) AS Earned
Go to Top of Page

hbadministrator
Posting Yak Master

120 Posts

Posted - 2014-02-14 : 11:54:58
how can I fix this. I am getting a divide by 0

CAST(ROUND(dbo.HB_JL_JobCost.TotalTD / dbo.HB_JL_JobCost.EstimateCost * 100, 2) * dbo.job.[sched-value] AS Numeric(16 , 2)) AS Earned
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2014-02-17 : 10:46:28
Select dividend / nullif(divisor, 0) ...


Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page
   

- Advertisement -