Solved

How to create a percentage from a query

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

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

705 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