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
 General SQL Server Forums
 New to SQL Server Programming
 Calculating the Average

Author  Topic 

archana23
Yak Posting Veteran

89 Posts

Posted - 2013-12-03 : 10:12:39
Hi,

I am calculating the average number of patients per day as like this

COUNT(DISTINCT PATIENTNAME) * 1.0/NullIf(COUNT(DISTINCT COALESCE(ARRIVEDATE,DEPARTDATE)),0) AS [AvgNo.ofpatients PerDay]

but i am getting results as like this 5.111111111111 , 8.000000000000,1.000000000000

we don't want to get that many digits after point we want only two digits like this 5.11,8.00 or 8, 1.00 or 1.

How can i do this?

can any one please help me on this?

Thanks,

Archana

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-12-03 : 10:33:56

convert(numeric(6,2), <your calculation sql>)

Cheers
MIK
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-03 : 23:42:37
Also ROUND(COUNT(DISTINCT PATIENTNAME) * 1.0/NullIf(COUNT(DISTINCT COALESCE(ARRIVEDATE,DEPARTDATE)),0),2) AS [AvgNo.ofpatients PerDay]

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

- Advertisement -