Solved

Calculated Column to calculate Ratio

Posted on 2007-03-26
4
668 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

914 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

17 Experts available now in Live!

Get 1:1 Help Now