473,388 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Expressing Values as Percentages

I have two values and I want to express a third derived value as a
percentage of the other two values. I thought it would be a simple
division of the first two numbers and then a multiplication by 100 to
give me a percentage, but all I get is 0.
Here is my select statement,

SELECT dbo.Eligble.GRADETotal,
dbo.nil1234_Faculties_Totals.FACTotal,
dbo.nil1234_Faculties_Totals.FACTotal /
dbo.Eligble.GRADETotal * 100 AS [PERCENT]
FROM dbo.Eligble CROSS JOIN
dbo.nil1234_Faculties_Totals
Can anyone point out where I'm going wrong here?

Thanks in advance
Jul 20 '05 #1
2 12576

"Bryan" <bm******@rics.org.uk> wrote in message
news:99*************************@posting.google.co m...
I have two values and I want to express a third derived value as a
percentage of the other two values. I thought it would be a simple
division of the first two numbers and then a multiplication by 100 to
give me a percentage, but all I get is 0.
Here is my select statement,

SELECT dbo.Eligble.GRADETotal,
dbo.nil1234_Faculties_Totals.FACTotal,
dbo.nil1234_Faculties_Totals.FACTotal /
dbo.Eligble.GRADETotal * 100 AS [PERCENT]
FROM dbo.Eligble CROSS JOIN
dbo.nil1234_Faculties_Totals
Can anyone point out where I'm going wrong here?

Thanks in advance


It would be useful to see your table DDL (CREATE TABLE statements), but the
most likely reason is that you're dividing two integers. Dividing integers
always gives an integer result:

select 6 / 10 -- gives 0

select 6.0 / 10.0 -- gives 0.6

In your case, you could use CAST() or CONVERT() to change the values to
decimal with a suitable precision/scale for your calculations, eg.:

(cast(FACTotal as decimal(10,4)) / cast(GRADETotal as decimal(10,4)))* 100
AS [PERCENT]

Simon
Jul 20 '05 #2
"Simon Hayes" <sq*@hayes.ch> wrote in message news:<3f********@news.bluewin.ch>...
"Bryan" <bm******@rics.org.uk> wrote in message
news:99*************************@posting.google.co m...
I have two values and I want to express a third derived value as a
percentage of the other two values. I thought it would be a simple
division of the first two numbers and then a multiplication by 100 to
give me a percentage, but all I get is 0.
Here is my select statement,

SELECT dbo.Eligble.GRADETotal,
dbo.nil1234_Faculties_Totals.FACTotal,
dbo.nil1234_Faculties_Totals.FACTotal /
dbo.Eligble.GRADETotal * 100 AS [PERCENT]
FROM dbo.Eligble CROSS JOIN
dbo.nil1234_Faculties_Totals
Can anyone point out where I'm going wrong here?

Thanks in advance


It would be useful to see your table DDL (CREATE TABLE statements), but the
most likely reason is that you're dividing two integers. Dividing integers
always gives an integer result:

select 6 / 10 -- gives 0

select 6.0 / 10.0 -- gives 0.6

In your case, you could use CAST() or CONVERT() to change the values to
decimal with a suitable precision/scale for your calculations, eg.:

(cast(FACTotal as decimal(10,4)) / cast(GRADETotal as decimal(10,4)))* 100
AS [PERCENT]

Simon

Simon,

Thanks for the response. Your solution worked a treat :)

thanks again

Bryan
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Avinash Dhoot | last post by:
Hi, I have a 5 row table with the following values. key value 1 5 2 10 3 15 4 15 5 5
0
by: michael | last post by:
I've got a 3-column layout using percentages to define width of each div-column. #left-col { width: 20%; background-color: green; float:left; } #center-col { width: 60%; background-color: blue;...
2
by: robbiehenry | last post by:
I built my company's website and the content portion of the site uses text with styles with relative values and the navigational part of the site uses text with styles with absolute values. The...
5
by: darrel | last post by:
(apologies if I've asked this before in here...I thought I had, but can't seem to find my original post). I'm trying to automate the process of picking some colors. I want to select one color,...
26
by: Mike Barnard | last post by:
Hi all. I am playing with html and css. I don't (yet) have a working site, I'm just trying to build a working, basic template I can use for a couple of ideas I have. I recall reading a...
5
by: Chris H | last post by:
I am wanting to write a function for a poker league manager that will detrmine players finishing points in a tournament depending on the amount of players that played... In other words when the...
1
by: Bob Alston | last post by:
I need to produce a report like this Color: # % ------ --- --- White 10 20 Black 25 50 other 15 30 ---- ---- Total 50 100
4
by: J | last post by:
I am editing a pre-existing view. This view is already bringing data from 40+ tables so I am to modify it without screwing with anything else that is already in there. I need to (left) join it...
9
by: AZKing | last post by:
Hi all, I would like to know how do you go about calculating percentages in Access. For example, in a form I have 3 combo boxes with drop down menus where a user can select "Yes" or "No" and a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.