473,473 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

95th percentile and Median functions in SQL server 2008/2005

1 New Member
Could some one guide if I can write code for 95th percentile or median function in SQL server 2008. My work place reports are very complex and we need an urgent solution to find out these fuctions?
If some one got dll file to assemble with SQL server that will be an ideal one to run this function as build in?

Regards
Ali
Jul 5 '11 #1
2 6138
Rabbit
12,516 Recognized Expert Moderator MVP
You don't need a function per se. If you wanted, you could write a function or a stored procedure. But you could do it by selecting the last record of the top 50 percent and the first record of the bottom 50 percent. Then you add them and divide by two.

A median is really a 50th percentile. To get a different percentile, you just need to use different numbers. For 95th percentile, you need the last record of the top 5 percent and the first record of the bottom 95 percent.
Jul 5 '11 #2
nbiswas
149 New Member
Hi,
Try this
Consider the sample input.(tblInput)

Expand|Select|Wrap|Line Numbers
  1. Numbers
  2. 10
  3. 20
  4. 30
  5. 40
  6. 50
The ddl is as under

Expand|Select|Wrap|Line Numbers
  1. Declare @tblInput table(Numbers int)
  2. Insert into @tblInput select  10 union all select 20 union all select 30 union all select 40 union  all select 50
Objective
To get the 95th percentile

Method to get so : Nearest rank.

Formula:
Expand|Select|Wrap|Line Numbers
  1. n = p/100 * N  + 0.5
So, for our example, the result will be
n= 95/100*5+0.5 =5.25
so the 95th percentile would be 50, the fifth number (since 5.25 rounds up to 5).


Expand|Select|Wrap|Line Numbers
  1. Declare @p int
  2. Declare @N int
  3. Declare @n numeric
  4. Set @p = 95
  5. Select @N = count(*) from @tblInput
  6. Select  @p/100 * @N + 0.5 
You can make this as a function and reuse it.

Hope this helps.

Reference:
Percentile
Jul 6 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: rcamarda | last post by:
I just downloaded the SQL Server 2008 CTP. Anyone here check it out yet? Thoughts?
1
by: GatorDBA | last post by:
Hey Folks, Experiencing strange problem with SQL 2005 running on Windows Server 2008. When trying to connect via named pipes or tcp, it takes 25-45 seconds for the connection to be established....
8
by: Andreas Zimmermann | last post by:
Hi, we just set up a SQL Server 2008 on Windows Server 2008 (configured as file / webserver, 16 GB memory, 4 dual core processors, 6 internal disks + 15 disc ISCSI array with overall almost 3 TB...
1
by: Chris O'C | last post by:
See: http://blogs.zdnet.com/microsoft/?p=1519 "Microsoft officials announced at TechEd South Africa on August 6 that SQL Server 2008 has been released to manufacturing. "Microsoft officials...
0
by: Fernan MC | last post by:
Hi, I am making a program using vb 2005 and using list and label 12 for the reports. I compiled the program and installed it in windows server 2008 but unfortunately the list and label will not...
1
by: =?Utf-8?B?QW50amU=?= | last post by:
I need product keys for Terminal Server Windows Server 2008 access (CALs) under MSDN - TSLM Service said they cannot provide product keys for the access.
0
by: abidthayyil | last post by:
Hello, I was working on SSRS 2005 as part of SQL Server 2005 Express Edition with Advanced Services Sp1. I successfully developed a custom reporting application. It was working fine. Then I...
6
by: AAaron123 | last post by:
I need to move a database from sql server 2008 to sql express 2008. Will backing up the sql server 2008 database to a file and then using that file to restore to sql express 2008 work? I don't...
0
by: zswanson | last post by:
Hello everyone, I am having a weird problem that I can't seem to find an answer to anywhere online so I thought I'd finally post a question. I am trying to connect to a remote SQL Server...
2
by: Vikram Raman | last post by:
Hello Everyone, I have developed a web application in asp.net with C# in visual Studio 2005. And i used sql server 2008 as back end. When i run the program, it shows the following error.....
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.