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 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2005-08-06 : 06:01:28
|
Hi All,I have the table Called Budget in which is there is column name called EmpID now if the EmpId -1 then its a vacant employee else its some occupied employee.EmpId Name1 XYZ2 ABC-1 Vacant-1 Vacant3 PORI want the following outputCount Type3 Occupied2 VacantThanks in Advance. Complicated things can be done by simple thinking |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-06 : 06:16:27
|
| Select sum(case when EmpId>0 then 1 else 0 end),'Occupied' from BudgetUnion allSelect sum(case when EmpId<0 then 1 else 0 end),'Vacant' from BudgetMadhivananFailing to plan is Planning to fail |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2005-08-06 : 06:27:45
|
| Thanks madhivanan.. u r really helpful.. but i would like to know this query cannot be done by group by Clause..???This worked perfectly for me.. Thanks once againComplicated things can be done by simple thinking |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-08-06 : 06:37:06
|
| Other possible method isselect count(Empid),'Occupied' from Budget where Empid>0Union allselect count(EmpId),'Vacant' from Budget where Empid<0Because you need extra column to specify Occupied or Vacant, it becomes complex if you do it in single queryMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|