Finding Ratio between two numbers

,

Call this function in your SP.Pass the arguments and get the result.

We searched a lot in WWW but could not find a code in SQL to find ratio.

When we wrote this simple thing..We thought letz share it across.Sharing is Expansion.

--Author Srikanth & Subin

--contact srikanthv1980@yahoo.com,subruj@yahoo.com

--Finding ratio in SQL
--Call this function in your SP and enjoy

create function FindRatio(@n1 int,@n2 int)

returns varchar(30)

as

begin

declare @counter int

declare @hcf int

declare @ratio varchar(30)

declare @max int

if((@n1=0) or (@n2=0))

begin 

set @ratio=convert(varchar,@n1)+':'+convert(varchar,@n2)

end

else

begin

if(@n1>@n2)

set @max=@n1

else

set @max=@n2

set @counter=2

while (@counter<=@max)

begin

if((@n1%@counter=0) and (@n2%@counter=0))

begin

set @hcf=@counter

set @n1=@n1/@hcf

set @n2=@n2/@hcf

end

else

begin

set @counter=@counter+1

end

end

set @ratio=convert(varchar,@n1)+':'+convert(varchar,@n2)

end

return @ratio

end

Rate

4.4 (5)

Share

Share

Rate

4.4 (5)