ALI ALI - 4 months ago 11
SQL Question

Hide column from the results set SQL select

I want to hide the

EMPNO
result from second select from displaying results because i already have it in first select SO, any ideas ??

select *from
(select M.EMPLOYEE_NUMBER,count(M.EMPLOYEE_NUMBER)as empnumcon,sum(C.MEMBER_PAID_AMOUNT)
from CPMS.ABDULLAH_MEMBERS M,CPMS.ABDULLAH_EMPLOYMENTS E,CPMS.ABDULLAH_SALARIES S,CPMS.ABDULLAH_CONTRIBUTIONS C
where M.MERGE_ID=E.MERGE_ID
and E.EMPLOYMENT_ID=S.EMPLOYMENT_ID
and S.SALARY_ID=C.SALARY_ID
group by M.EMPLOYEE_NUMBER)t1
inner join
(select EMPNO,count(EMPNO)as numfacon,sum(PENSND)
from CON1.PEN_DED
where PENSND !=0
group by EMPNO)t2
on t1.EMPLOYEE_NUMBER = t2.EMPNO

Answer

I Think Inspite of using * you should Select your Column Beacuse once You Select any Column it will appear in Result.

select t1.EMPLOYEE_NUMBER,
empnumcon
from
(select M.EMPLOYEE_NUMBER,count(M.EMPLOYEE_NUMBER)as empnumcon,sum(C.MEMBER_PAID_AMOUNT)
  from CPMS.ABDULLAH_MEMBERS M,CPMS.ABDULLAH_EMPLOYMENTS E,CPMS.ABDULLAH_SALARIES S,CPMS.ABDULLAH_CONTRIBUTIONS C
          where M.MERGE_ID=E.MERGE_ID
          and E.EMPLOYMENT_ID=S.EMPLOYMENT_ID
         and S.SALARY_ID=C.SALARY_ID
         group by M.EMPLOYEE_NUMBER)t1
          inner join
          (select EMPNO,count(EMPNO)as numfacon,sum(PENSND)
           from CON1.PEN_DED
          where PENSND !=0
          group by EMPNO)t2
         on t1.EMPLOYEE_NUMBER = t2.EMPNO

[Please refer this link][1]

http://www.sqlservercentral.com/Forums/Topic1361480-392-1.aspx