Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Blessed1978
Yak Posting Veteran
97 Posts |
Posted - 2014-06-16 : 23:34:01
|
i have the following SELECTs i would like to place them in just on statementselect count(*) as 'TOTAL EMPLOYEES' from employeeSELECT COUNT(*) AS 'TOTAL PEOPLE CALLED' FROM employee_DETAILSwhere call_type = 'call'SELECT COUNT(*) AS 'TOTAL PEOPLE met' FROM employee_DETAILSwhere call_type = 'meeting'so i created this query select count(E.employees) as 'TOTAL EMPLOYEES',COUNT(CASE WHEN ed.type = call then 1 else 0) end as 'TOTAL PEOPLE CALLED',COUNT(CASE WHEN ed.type = meeting then 1 else 0)end as 'TOTAL PEOPLE met'from employees einner join employee_details ed on e.employee_id = ed.employee_idhowever when i run this all counts are 0 please advise |
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-06-17 : 01:11:18
|
[code]COUNT(CASE WHEN call_typeed.type = 'call' then 1 else 0) end as 'TOTAL PEOPLE CALLED',COUNT(CASE WHEN call_typeed.type = 'meeting' then 1 else 0)end as 'TOTAL PEOPLE met'[/code]At my first view, you forgot the 'and in first query the predicate is call_type ed.typeIt's a typo ?sabinWeb MCP |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-06-21 : 05:30:18
|
also as you're using COUNT function it should be 1 and NULL rather than 1 and 0 as in latter case it will count 0s too and you'll get same count value for allselect count(E.employees) as 'TOTAL EMPLOYEES',COUNT(CASE WHEN ed.call_type = 'call' then 1 else NULL end) as 'TOTAL PEOPLE CALLED',COUNT(CASE WHEN ed.call_type = 'meeting' then 1 else NULL end) as 'TOTAL PEOPLE met'from employees einner join employee_details ed on e.employee_id = ed.employee_id ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|