Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 7th, 2007, 01:03 AM
Authorized User
 
Join Date: Oct 2006
Location: , , .
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



Reply With Quote
  #2 (permalink)  
Old May 7th, 2007, 01:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
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
Reply With Quote
  #3 (permalink)  
Old May 7th, 2007, 09:04 PM
Authorized User
 
Join Date: Oct 2006
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

More power to you!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:06 PM.


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