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 2000 Forums
 Transact-SQL (2000)
 percentages

Author  Topic 

kemi2299
Starting Member

41 Posts

Posted - 2008-03-06 : 05:51:43
I need your help, i am trying to calculate percentages using Tsql, do you have an idea of how i can define the statement. I understand i can use float but i am getting nowhere with it. i would appreciate your help.

eth_orig_ok = sum(eth_orig_flag), eth_orig_p= float4(null),
pcent_ethnic = float4((float4(sum_ethnic)/total_adms)*100),

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-06 : 06:05:32
pcent_ethnic = ((sum_ethnic*1.0)/total_adms)*100
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-06 : 06:09:21
Why all these paranthesises?

pcent_ethnic = 100.0 * sum_ethnic / total_adms



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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-06 : 08:22:22
<<
Why all these paranthesises?
>>

Too much precaution

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

kemi2299
Starting Member

41 Posts

Posted - 2008-03-06 : 09:52:24
hi guys,

thanks for your help, using your suggested solution, the result i am getting is 18.750000000000, which seem to be too long, so how can i give declare the statement to give 2 decimal places, that is 18.75 instead.

i believe thats where the float comes in, what do you think?

victoria
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2008-03-06 : 10:18:25
CONVERT... but why are you trying to format in SQL? That should be done in the app.

--Jeff Moden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-03-07 : 03:13:56
cast or convert to decimal(20,2)


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-07 : 04:27:36
quote:
Originally posted by madhivanan

<<
Why all these paranthesises?
>>

Too much precaution

Madhivanan

Failing to plan is Planning to fail


I tend to do it always
Go to Top of Page
   

- Advertisement -