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
 SQL Server Development (2000)
 stored procedures for accounting ratios

Author  Topic 

saurabhjj
Starting Member

13 Posts

Posted - 2007-08-31 : 08:05:05
hi,

i am working on a sytem where i need to calculate accounting ratios for a business, the data are to be retrieved from the database and i need to calculate the ratios, i am new to wrting stored procedures, so can any one help me out

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-31 : 09:06:24
ex

Create procedure calc_ratios
as
Select cols,1.0*somecol/othercol*100 as ratio from table

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-08-31 : 09:12:58
wouldn't

Select cols,100.0 * somecol / othercol * 100 as ratio from table

be enough?

also, beware of division by zero.
Select cols,100.0 * somecol / nullif(othercol, 0) as ratio from table



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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-31 : 09:18:45
quote:
Originally posted by Peso

wouldn't

Select cols,100.0 * somecol / othercol * 100 as ratio from table

be enough?

also, beware of division by zero.
Select cols,100.0 * somecol / nullif(othercol, 0) as ratio from table



E 12°55'05.25"
N 56°04'39.16"


Yes it is
When there are no hardcoded values, then I used to use 1.0 which in this case not needed

Madhivanan

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

- Advertisement -