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)
 Percent callculate query

Author  Topic 

sqldba2k6
Posting Yak Master

176 Posts

Posted - 2006-07-26 : 14:54:51
I need help in writing the script to get the percentage.
Below is the table data and formula:

YP TE NO xxpercent
--- -- -- -----
veonal 3 7 %
Aid 3 7 %

Formula:
for each yp (Ex:veonal,Aid etc):
TE divided by No x 100 = xx%

veonal:3/7 *100

aid:3/7*100

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-26 : 15:30:45
What part are you having a problem with? Just put the column names instead of the values.

SELECT ColumnName1/ColumnName2 * 100
FROM YourTable

To update your column:

UPDATE YourTable
SET YourColumn = FormulaFromAbove

Tara Kizer
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-07-26 : 15:34:34


But Tara try my code snipet with out the *1.0


USE Northwind
GO

CREATE TABLE myTable99(YP char(10), TE int, [NO] int)
GO

INSERT INTO myTable99(YP,TE,[NO])
SELECT 'veonal', 3, 7 UNION ALL
SELECT 'Aid' , 3, 7
GO

SELECT YP, (TE*1.0/[NO])*100
FROM myTable99
GO

DROP TABLE myTable99
GO




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-26 : 15:50:04
quote:
Originally posted by X002548



But Tara try my code snipet with out the *1.0




It just depends on the data types. If either of them are decimal or numeric, then you don't need the 1.0. It has to do with data type precedence. But yes if the data types are ints, you'll definitely need the 1.0, otherwise you won't get the value that you are expecting back.

Tara Kizer
Go to Top of Page
   

- Advertisement -