Solved

Percentile function

Posted on 2002-06-28
4
588 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Generate Scripts Fails 5 36
string fuctions 4 26
Get the latest status 8 32
Loops and updating in SQL Query 9 29
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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 backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

810 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