[dba-SQLServer] formatting a number to 2 decimal places.

Klos, Susan Susan.Klos at fldoe.org
Wed Aug 4 07:31:58 CDT 2004


I am a newbie to SQL Server and have been pretty much applying my Access
knowledge of SQL to SQL Server.  I have created three views.  The first one
finds the number of students in schools by district and school number.  The
next one creates a weighted school gpa for each school and then sums this
and school enrollment by district.  The last one finds a weighted gpa for
the district.  The result shows up as an integer.  I would like to have the
result show up rounded to 2 decimals.  How and at what step do I do that?
Here is the code for the views:

 

Create Total School Enrollment by district and school

CREATE VIEW dbo.SchoolEnrollmentNumbersXDistschl

AS

SELECT     TOP 100 PERCENT DistEnrl, SchlEnrl, DistEnrl + SchlEnrl AS
distschl, COUNT(SID) AS TotSchlEnrl

FROM         dbo.Survey3

GROUP BY DistEnrl, SchlEnrl

ORDER BY distschl

 

Create weighted school gpa and Sum weighted school gpa and total school
enrollment by district

CREATE VIEW dbo.WTGPAPtsXDist

AS

SELECT     arm_klos.GradedSchools.distenrl, arm_klos.GradedSchools.distname,
SUM((arm_klos.GradedSchools.gr04 - 1) 

                      * dbo.SchoolEnrollmentNumbersXDistschl.TotSchlEnrl) AS
wtgpa1, SUM(dbo.SchoolEnrollmentNumbersXDistschl.TotSchlEnrl) AS EnrlTot

FROM         arm_klos.GradedSchools INNER JOIN

                      Dbo.SchoolEnrollmentNumbersXDistschl ON
arm_klos.GradedSchools.distenrl =
dbo.SchoolEnrollmentNumbersXDistschl.DistEnrl AND 

                      arm_klos.GradedSchools.schlenrl =
dbo.SchoolEnrollmentNumbersXDistschl.SchlEnrl

WHERE     (arm_klos.GradedSchools.SchoolType = N'elem')

GROUP BY arm_klos.GradedSchools.distenrl, arm_klos.GradedSchools.distname

 

Create District Weighted GPA

CREATE VIEW dbo.DistWGPA

AS

SELECT     distenrl, distname, wtgpa1 / EnrlTot AS wgpa

FROM         dbo.WTGPAPtsXDist

 

 

Susan Klos

Senior Database Analyst

Evaluation and Reporting

Florida Department of Education

850-245-0708 

sc 205-0708

 




More information about the dba-SQLServer mailing list