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.
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 *100aid: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 * 100FROM YourTableTo update your column:UPDATE YourTableSET YourColumn = FormulaFromAboveTara Kizer |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2006-07-26 : 15:34:34
|
But Tara try my code snipet with out the *1.0USE NorthwindGOCREATE TABLE myTable99(YP char(10), TE int, [NO] int)GOINSERT INTO myTable99(YP,TE,[NO])SELECT 'veonal', 3, 7 UNION ALLSELECT 'Aid' , 3, 7GOSELECT YP, (TE*1.0/[NO])*100 FROM myTable99GODROP TABLE myTable99GO Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
|
|
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 |
|
|
|
|
|
|
|