Click here to Skip to main content
11,411,494 members (64,526 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005
Hello

I am using pivot in sql server like

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 18-Feb-13 19:58pm
Comments
RedDK at 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)

  Print Answers RSS
0 OriginalGriff 213
1 Sergey Alexandrovich Kryukov 149
2 Sascha Lefévre 110
3 Dave Kreskowiak 90
4 RyanDev 75
0 Sergey Alexandrovich Kryukov 8,920
1 OriginalGriff 6,983
2 Maciej Los 3,430
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web04 | 2.8.150414.5 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100