SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Calculating the Average
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

archana23
Yak Posting Veteran

74 Posts

Posted - 12/03/2013 :  10:12:39  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Pakistan
1052 Posts

Posted - 12/03/2013 :  10:33:56  Show Profile  Reply with Quote

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

Cheers
MIK
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 12/03/2013 :  23:42:37  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000