Results 1 to 5 of 5
  1. #1
    Join Date
    May 2004
    Posts
    28

    Unanswered: decimal point problem

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

    vbScript
    Code:
    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:
    Code:
    CREATE PROCEDURE quarterFinalGradeSA @nClass INT, @nQuarter INT, @nStudent INT AS
    
    SELECT (SUM(tblScores.score) / SUM(tblAssignments.assignmentTotalPoints)) AS returnValue
    ...

  2. #2
    Join Date
    May 2004
    Posts
    28
    oops I should have given more vbScript
    Code:
    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.

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'd use:
    Code:
    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

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by Pat Phelan
    I'd use:
    Code:
    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...

    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •