Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 ratios

Author  Topic 

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-01-18 : 10:59:33
hi,
I have 2 fields sum and count.
sum = 720
count = 400

so far I have the ration 720:400

Do you know how I can use SQL to show the smallest ratio ?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-01-18 : 11:09:10
Not clear what you want. Post the table structures, sample data and expected output.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-01-18 : 11:22:53
60:20 is a 3:1 ratio.

I have table1 with field1 and field2 , so far I do
convert(varchar,field1) + ':'+ convert(carchar,field1)
This is displayed as 60:20

but I need to work out the smallest ratio..
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-01-18 : 11:39:24
[code]declare @Value1 int
declare @Value2 int
set @Value1 = 720
set @Value2 = 400

select top 1000
IDENTITY(int, 1,1) as Value
into #SequentialValues
from master..spt_values A,
master..spt_values B

select @Value1/max(Value) as Value1,
@Value2/max(Value) as Value2
from #SequentialValues
where @Value1 % Value = 0
and @Value2 % Value = 0

drop table #SequentialValues[/code]

e4 d5 xd5 Nf6
Go to Top of Page

jamie
Aged Yak Warrior

542 Posts

Posted - 2008-01-18 : 11:41:04
thank you so much !
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-18 : 16:38:40
Or use the function fnLCM described here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=73610&whichpage=2




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -