Solved

How to create a percentage from a query

Posted on 2009-04-05
2
290 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
Comment Utility
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
Comment Utility
have you tried like this?

select columnA/columnB * 100.0 from tablename
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

771 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

12 Experts available now in Live!

Get 1:1 Help Now