Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Calculated Column to calculate Ratio

Posted on 2007-03-26
Medium Priority
678 Views
Hi there I want to do the following calculated column from in this query.

SELECT
max(dbo.getmonthdate(t.TransDate)),
max(dbo.getmonth(t.TransDate)),
Sum(CASE t.TransType WHEN 1 THEN 1 ELSE 0 END) AS PassportsIssued,
Sum(CASE t.TransType WHEN 7 THEN 1 ELSE 0 END) AS PassportVerifications,
Sum(CASE t.TransType WHEN 8 THEN 1 ELSE 0 END) AS SkillVerifications,

I want  column that does...

(PassportVerifications/SkillVerifications) / PassportsIssued

Can Anyone Help
0
Question by:MayoorPatel
[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

LVL 11

Accepted Solution

Otana earned 1000 total points
ID: 18791908
(Sum(CASE t.TransType WHEN 7 THEN 1 ELSE 0 END)/Sum(CASE t.TransType WHEN 8 THEN 1 ELSE 0 END))/Sum(CASE t.TransType WHEN 1 THEN 1 ELSE 0 END) AS PassportsIssued AS Calculated
0

LVL 2

Assisted Solution

jhshen earned 1000 total points
ID: 18793621
You may try this one:
SELECT T1.*, (T1.PassportVerifications/T1.SkillVerifications) / T1.PassportsIssued  As Ratio from (
SELECT
max(dbo.getmonthdate(t.TransDate)) As TransDate,
max(dbo.getmonth(t.TransDate)) As TransMonth,
Sum(CASE t.TransType WHEN 1 THEN 1 ELSE 0 END) AS PassportsIssued,
Sum(CASE t.TransType WHEN 7 THEN 1 ELSE 0 END) AS PassportVerifications,
Sum(CASE t.TransType WHEN 8 THEN 1 ELSE 0 END) AS SkillVerifications,
...) As T1
0

## Featured Post

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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â€¦
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
###### Suggested Courses
Course of the Month9 days, left to enroll