so, i'll have to hardcode the VP value for each case? i could write a for loop? got some reading to do..
Main Topics
Browse All TopicsHi-
I want to get #complete, #incomplete, vp
i have table users, completes.
heres my non-working query:
select vp, COUNT(*) as [ALL By VP],
(Select count(*)
from users
join completes on Users.[User id] = completes.[user id]
where [Transcript Status] = 'Completed'
)
as [count compl] --totally innaccurate number
from users
group by vp
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
thanks- any idea why i get 0 for my percentage?
select vp, COUNT(*) as [ALL By VP],
SUM(CASE [Transcript Status] WHEN 'Completed' THEN 1 ELSE 0 END) AS [count compl],
SUM(CASE [Transcript Status] WHEN 'Completed' THEN 0 ELSE 1 END) AS [count incompl],
(SUM(CASE [Transcript Status] WHEN 'Completed' THEN 1 ELSE 0 END) / count(*))*100 AS [percent compl]
from users u
left outer join completes c on u.[User id] = c.[user id]
group by vp
;
MS SQL Servers '/' operator will always do integer division on integers. It will not convert to decimal / fractional results like you may be use to with other programming languages (i.e., there is no separate integer division operator it is based on datatype of the operands).
With that said (hopefully clear), you have to ensure that the equation involves a non-integer. This is one of the ways to achieve that easily.
select vp, COUNT(*) as [ALL By VP],
SUM(CASE [Transcript Status] WHEN 'Completed' THEN 1 ELSE 0 END) AS [count compl],
SUM(CASE [Transcript Status] WHEN 'Completed' THEN 0 ELSE 1 END) AS [count incompl],
(SUM(CASE [Transcript Status] WHEN 'Completed' THEN 1 ELSE 0 END) * 100.0 / count(*)) AS [percent compl]
from users u
left outer join completes c on u.[User id] = c.[user id]
group by vp
;
If you want the result to certain decimal places, you can cast / convert and even round appropriately.
M-1
Business Accounts
Answer for Membership
by: tigin44Posted on 2009-11-05 at 06:35:54ID: 25749833
try this
select vp, count(*),
count(case when [Transcript Status] = 'Completed' then 1 else 0 end ) as Completed
from users
join completes on Users.[User id] = completes.[user id]