Solved

Calculated Column to calculate Ratio

Posted on 2007-03-26
4
672 Views
Last Modified: 2012-06-27
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
Comment
Question by:MayoorPatel
4 Comments
 
LVL 11

Accepted Solution

by:
Otana earned 250 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

by:jhshen
jhshen earned 250 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Insert to Begin if data exists 2 33
SQL Backup Question 2 30
First Max value 3 31
SQL Find Carriage Return and Delete it. 3 13
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

827 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