tags:

views:

71

answers:

3
+1  Q: 

Get over points

Hello,

I am writing a function to get overall score in SQL

What I have is;

out of 20 points I got 12.4 points

so if I transform that, to take percentage over 100% how would I do it?

Thanx, Adnan

+3  A: 

Divide the points you've got by the total, and multiply by 100:

select [got] / [total] * 100
from MyTable
Andomar
thanx, that is it
Adnan
A: 

(12.4 / 20) x 100 will give the percentage.

So declare a percentage variable in your func, use the above and return that?

Jammin
A: 

Presuming you mean fuction as in stored procedure, it would look like this in oracle

create or replace function pct
    (p_score in number
     , p_total in number)
    return number
    deterministic
is
begin
    return p_score * (100/p_total);
end;
/

Different flavours of database have different specifications for writing stored procedures.

APC
APC, yours is even better, thank you.
Adnan
Hmm, not sure I deserve those rep points, as Adnan awarded them while I completely rewrote my answer, from a SQL query to an sproc.
APC