How to convert row data into column?
My query is
select distinct b.Emp_Name,a.emp_id,a.date,a.status,b.Emp_F_H开发者_Python百科,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
I want Output like
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....
so how i dynamicaly generate 31 colum For single emp id to status column plz help me
Try this article
Crosstab Pivot-table Workbench
http://www.simple-talk.com/sql/t-sql-programming/crosstab-pivot-table-workbench/
精彩评论