2011-10-04 187 views
-1

我的查詢是如何將行數據轉換爲列?

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.... 

所以我怎麼dynamicaly產生31科拉姆對於單EMP ID到狀態欄plz幫助我

+1

什麼數據庫和版本? –

+7

搜尋PIVOT –

回答