?
Solved

How to create a percentage from a query

Posted on 2009-04-05
2
Medium Priority
?
302 Views
Last Modified: 2012-05-06
How do I create a percentage from a query. Suppose I have a table named myTable with a Column named "A" and a column named "B". How can I perform a query resulting in a percentage of A divided by B? I imagine I do something like (A/B) * 100, but I don't know how to set up the query. Can someone please help me out?
0
Comment
Question by:brgdotnet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 1040 total points
ID: 24073708
Hello brgdotnet,

If at least one of A or B is not int, smallint, or bigint...

SELECT A, B, 100 * A / B AS Perc
FROM SomeTable

If both are int, smallint, or bigint...

SELECT A, B, 100.0 * A / B AS Perc
FROM SomeTable

Regards,

Patrick
0
 
LVL 39

Assisted Solution

by:appari
appari earned 160 total points
ID: 24073710
have you tried like this?

select columnA/columnB * 100.0 from tablename
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question