Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Number

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-03-23 : 13:40:31
Hello,

I am creating an average rating as follows:
SELECT @AvgDocRating = ROUND(AVG(DocRating), 0)
FROM Docs

DocRating is of type TinyInt

However, I want to change this to return not a integer but a double with two decimal places such as:
2.32, 4.34, 2.67, ...

How can should my code become and what data type should I use to AvgDocRating?

Thanks,
Miguel

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-03-23 : 13:56:06
[code]
declare @AvgDocRating decimal(10,2)

SELECT
@AvgDocRating = ROUND(AVG(convert(decimal(10,2),DocRating)),2)
FROM
Docs

[/code]


CODO ERGO SUM
Go to Top of Page
   

- Advertisement -