Solved

How to create a percentage from a query

Posted on 2009-04-05
2
291 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
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 260 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 40 total points
ID: 24073710
have you tried like this?

select columnA/columnB * 100.0 from tablename
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

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…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now