Solved

Percentile function

Posted on 2002-06-28
4
590 Views
Last Modified: 2007-11-27
HI

I badly need a percentile function, it something like this

 getPercentile (value,set)

I am hoping that there might be an extended stored
procedure or something similar that we can use.

Currently we do not have the option of using SQL 2000
Analysis Services.

Any help is greatly appreciated.

Thanks,
syam
0
Comment
Question by:syamsundar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:David Todd
ID: 7123540
Hi,

Are you using SQL 2000?

Can this be writtern as a user defined function?

Regards
  David
0
 

Author Comment

by:syamsundar
ID: 7124527
Yes i am using sql 2000. A user defined function will do.
0
 
LVL 35

Accepted Solution

by:
David Todd earned 50 total points
ID: 7125568
Hi,

Isn't the percentile just the score / possible * 100?

Is this what you are looking for?

drop function Percentile
go

create function Percentile( @score as integer, @Possible as integer )
returns integer
as
begin
     declare @Percent     integer

     if @Possible != 0
          set @Percent = ( cast( @Score as float ) * 100.0 / cast( @Possible as float ))
     else
          set @Percent = 0

     return( @Percent )
 
end

select dbo.Percentile( 43, 233 ) as percentile


gives

percentile  
-----------
18

(1 row(s) affected)

Note that I had to cast the parameters to floats to get the division to work, and also moved the * 100 to get better accuracy.

Regards
  David
0
 

Author Comment

by:syamsundar
ID: 7127131
todd,

Thank you very much.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question