Wednesday, March 7, 2012

decimal point problem

I want to force two places to the right of the decimal even if its a whole number.

vbScript

calculatedScore = FormatNumber((rsQFinal("sumEarned") / rsQFinal("sumPossible")) * 100, 2)

I'm not savy enought to know the SQL equivalent of the above but I'd like SQL Server to perform the above rather than my vbScript code.

heres what I have so far but I don't know the formatNumber equivalent:

CREATE PROCEDURE quarterFinalGradeSA @.nClass INT, @.nQuarter INT, @.nStudent INT AS

SELECT (SUM(tblScores.score) / SUM(tblAssignments.assignmentTotalPoints)) AS returnValue
...oops I should have given more vbScript

If rsQFinal("sumEarned") = 0 Then
calculatedScore = 0
Else
calculatedScore = FormatNumber((rsQFinal("sumEarned") / rsQFinal("sumPossible")) * 100, 2)
End If

It is possibel for sumEarned to be 0 which won't do well in the division problem, is there a way to do the conditional in the SQL as well.|||I'd use:CREATE PROCEDURE quarterFinalGradeSA @.nClass INT, @.nQuarter INT, @.nStudent INT AS

SELECT (CAST CASE WHEN 0 = SUM(tblAssignments.assignmentTotalPoints) THEN 0.0 ELSE 1e2 * SUM(tblScores.score) / SUM(tblAssignments.assignmentTotalPoints) AS NUMERIC(5, 2)) AS returnValue
...-PatP|||I'd use:CREATE PROCEDURE quarterFinalGradeSA @.nClass INT, @.nQuarter INT, @.nStudent INT AS

SELECT (CAST CASE WHEN 0 = SUM(tblAssignments.assignmentTotalPoints) THEN 0.0 ELSE 1e2 * SUM(tblScores.score) / SUM(tblAssignments.assignmentTotalPoints) AS NUMERIC(5, 2)) AS returnValue
...-PatP

Don't you get bored?

I thougt you had a girlfriend...

:D|||I get to see the girlfriend and kids on weekends (notice you rarely see a post from me on Saturday or Sunday, except for early in the mornings?). During the week I have to "batch" it, either on the road or at the Data Center.

-PatP

No comments:

Post a Comment