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 |
|
swathigardas
Posting Yak Master
149 Posts |
Posted - 2008-11-11 : 01:04:39
|
| Hi . select count(e.employee_nbr) as total, sum(case when e.Active_Flag=1 Then 0 else 1 end) as Active_Employees, Total-Active_Employees As Inactve_Employees FROM TEmployee eWhen i Execute the Above query i get an error like below-Msg 207, Level 16, State 1, Line 3Invalid column name 'Active_Flag'.Msg 207, Level 16, State 1, Line 4Invalid column name 'Total'.Msg 207, Level 16, State 1, Line 4Invalid column name 'Active_Employees'.Cant i use alias names of result set for subtractionSuggest me how can i do it.Thanks in AdvanceSwathi |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-11 : 01:12:44
|
you cant directly use them. you need to make a derived table and then use from itselect total,Active_Employees,Total-Active_Employees As Inactve_Employeesfrom(select count(e.employee_nbr) as total,sum(case when e.Active_Flag=1 Then 0 else 1 end) as Active_EmployeesFROM TEmployee e)t |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-11 : 01:13:43
|
| Also make sure you've Active_Flag column available in TEmployee table. |
 |
|
|
swathigardas
Posting Yak Master
149 Posts |
Posted - 2008-11-11 : 02:44:59
|
| Thanks Vishakh. I've got it |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-11 : 03:15:26
|
Welcome |
 |
|
|
|
|
|
|
|