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 Maciej Los 295
1 OriginalGriff 273
2 Aajmot Sk 234
3 Marcin Kozub 205
4 Richard MacCutchan 200
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.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