try this:create table emp(e_id int,date datetime)insert into empselect 10210, '2010/03/05' union allselect 10210, '2010/03/08' union allselect 10211, '2010/03/02' union allselect 10213, '2010/03/04' create table date(id int identity(1,1),date datetime)insert into dateselect '2010/03/01' union allselect '2010/03/02' union allselect '2010/03/03' union allselect '2010/03/04' union allselect '2010/03/05' union allselect '2010/03/06' union allselect '2010/03/07' union allselect '2010/03/08' select e,[1],[2],[3],[4],[5],[6],[7],
from(select e.e_id as emp ,day(d.date)as days ,e.e_id as e from date as d left join emp as e on d.date = e.date) as pPIVOT( count(emp) for days in ([1],[2],[3],[4],[5],[6],[7],
) )as pivotTBLwhere pivotTBL.e is not nulldrop table empdrop table date