如何将行数据转换为列?

时间:2011-10-04 04:33:15

标签: sql sql-server sql-server-2005 tsql

我的查询是

select distinct b.Emp_Name,a.emp_id,a.date,a.status,b.Emp_F_H,b.Emp_Gender,b.Emp_DOJ,c.Dept_Disc
from dbo.Attendance_Details a
inner join dbo.Employee_Master b on a.emp_id=b.emp_id
inner join dbo.Department_Details c
  on b.Dept_Id=c.dept_id 
    and a.Fromdate='2011-09-01 00:00:00.000'
    and a.todate='2011-09-30 00:00:00.000'
order by b.emp_name

我想输出

emp_name emp_id  emp_f_h doj      emp_gender  dept 1 2 3 4 5..upto 31 column for status 
kamal    emp_1  b.singh  1/1/2011  male      hr   p A P P P...upto 31
ramesh emp_2  singh  1/1/2011  male          Fc   p A P P P...upto 31....

所以我如何动态生成31列对于单个emp id到状态列plz帮助我

1 个答案:

答案 0 :(得分:0)