Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello

I am using pivot in sql server like

SQL
select * from (select emp_code,emp_name,Allowance_Name,Allwance_Amount from V_Acquintance_role where emp_code='E004') s
pivot (max(Allwance_Amount) for Allowance_Name in([ESI],[PF],[HRA],[Other Deduction]) ) pt

this is running fine and i am getting the correct output also but,  "([ESI],[PF],[HRA],[Other Deduction])" this thing is constant which i want to make dynamic meand the data will come from database by which i have used the following code but it is showing error.

select * from (select emp_code,emp_name,Allowance_Name,Allwance_Amount from V_Acquintance_role where emp_code='E004') s
pivot (max(Allwance_Amount) for Allowance_Name in(select Allowance_Name from dbo.tbl_Allowance_Master) ) pt



Any solution please help.


Thanks.
Posted
Comments
RedDk 19-Feb-13 16:36pm    
http://www.codeproject.com/Questions/548618/PivotplusExampleplusinplusSQLplusServer
This nice example uses AdventureWorks2008

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900