• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1419
  • Last Modified:

How calculate percentage

I already have two complex queries returning numeric values; so, in order to get the percentage value I need to use a formula:  (query1 / query2)*100, and, could be even better applying a percentage mask&.
0
moralesrd
Asked:
moralesrd
1 Solution
 
Kevin CrossChief Technology OfficerCommented:
Think this should work (value is column name returned from your queries -- believe cross join will work since you only have one record/value in each -- can try outer apply also unless you can use a stored procedure then I would set each value to a @variable and then use them in calculation like I show below):
SELECT 
CASE q2.[value] WHEN 0 THEN 0
ELSE q1.[value] * 100.0/q2.[value] END AS [Percentage]
FROM (query1) AS q1
CROSS JOIN (query2) AS q2

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now