Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 7th, 2007, 01:03 AM
Authorized User
 
Join Date: Oct 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using AVG aggregate function with decimal

Hi,

I am using AVG function in one of my Views to create summary of records. The View works fine except that the average displays whole numbers only. I even tried using ROUND function, but still the AVG function gets whole numbers only. Anyone who has idea on this? Thanks so much!


SELECT ProjectID, BatchCode, WeekNo,
ROUND(AVG completionratetotal), 2) AS WeeklyCompletionAverage
FROM dbo.CompletionRateTotalNoNegativeView
GROUP BY ProjectID, BatchCode, WeekNo



 
Old May 7th, 2007, 01:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

What is the datatype of "completionratetotal" column? If that is already a decimal type, you dont have to manipulate it to get decimals. ROUND function is used to round the value to specific decimals points.

I doubt the completionratetotal is an INT type defined in the table. In this case you need to typecast the completionratetotal's value to decimal by using
Code:
CAST(AVG(completionratetotal) as DECIMAL(10,2))
Hope that helps.

cheers.

_________________________
- Vijay G
Strive for Perfection
 
Old May 7th, 2007, 09:04 PM
Authorized User
 
Join Date: Oct 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi ViJay,
Thanks for the help! It works! :)

More power to you!






Similar Threads
Thread Thread Starter Forum Replies Last Post
aggregate function polofson BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 0 August 14th, 2007 01:29 PM
Aggregate function MAX creating problem..? Manu SQL Language 4 May 30th, 2006 04:41 AM
Aggregate Function MAX, SUM Manu SQL Language 2 May 30th, 2006 04:40 AM
Aggregate Function Adamcg Access 3 December 5th, 2005 09:24 AM
Count aggregate function Robert_Hill BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 August 24th, 2004 01:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.