Solved

How to create a percentage from a query

Posted on 2009-04-05
2
295 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Nested Case statement 4 39
SQL, add where clause 5 24
AD and SQL Server 2016 2 31
Run Stored Procedure uisng ADO 5 23
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

821 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