?
Solved

Percentile function

Posted on 2002-06-28
4
Medium Priority
?
592 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 200 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

765 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