SQLTeam.com | Weblogs | Forums

Pivot column

sql2008

#1

hey guys, i need to make the data in the column to be column head

this is the current result from my query .. :

select employee_id,reimbursement_type,SUM(amount) as [total amount],reimbursement_status from md_reimbursement
group by employee_id,reimbursement_type,reimbursement_status

and what i want is like this :

employee id | Biaya Dinas | Other | Transport | Uang Makan | Status
50006 | 1320484848 | 500 | 150 | 500 | APPROVED

the data in column reimbursement_type converted into column head and sum its amount.

i knew i have to use pivot, but i still dont get the right query.
thx


#2

I noticed for "Transport", one reimbursement was approved and the other one not, yet in your desired output you add them up (100 + 50 = 150) and show the total as "approved". Similarly for the cancelled and rejected ones. That doesn't sound right. Please confirm


#3

just ignore the status column