Click here to Skip to main content
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 315
1 Jochen Arndt 190
2 DamithSL 125
3 PIEBALDconsult 110
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
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