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 2008 Forums
 Transact-SQL (2008)
 Avg Decimals

Author  Topic 

jamesingamells
Starting Member

11 Posts

Posted - 2013-10-22 : 05:20:27
Hi,

I am having an issue with an averageg i am trying to calculate. Here is the query. The results i am getting back are 27.00, 12.00 etc, when they should be 27.38, 12.67 etc.

Any advice?

SELECT
Week,
Hospital,
CAST( avg(Length_Of_Stay) AS DECIMAL(10,2)) as Average_LoS

FROM table

GROUP BY
Week,
Hospital

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-10-22 : 05:58:34
SELECT
Week,
Hospital,
CAST( avg(Length_Of_Stay*1.0) AS DECIMAL(10,2)) as Average_LoS


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-22 : 07:49:54
should be this i guess

SELECT
Week,
Hospital,
avg(CAST(Length_Of_Stay AS DECIMAL(10,2))) as Average_LoS

FROM table

GROUP BY
Week,
Hospital


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-22 : 07:50:44
reason is this
http://beyondrelational.com/modules/2/blogs/70/posts/10825/beware-of-implicit-conversions.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -