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

I have a table that have records like this -



Particluar-------------------------------------Amount

Excise Duty 12 % ---------------------------- 2775.00
Edu CESS 2% -------------------------------- 56.00
HR Edu CESS 1% ---------------------------- 28.00
Sale CST 2% --------------------------------- 520.00

and I would like to get the following from select query

Excise Duty 12 % ---- Edu CESS 2% ---- HR Edu CESS 1% ---- Sale CST 2%
2775.00 ----------------- 56.00 ------------- 28.00 ------------- 520.00


If it possible then please reply me its urgent...
Thanx in advance....
Posted
Updated 30-Apr-13 0:00am
v2

You can try like this:-


SQL
declare @columns varchar(max)
declare @convert varchar(max)
select @columns =stuff((select '],[' + particular from tblName order by '],['
                                   + convert(varchar(max),points) desc
                                     for xml path('')),1,2,'') + ']'

--Select @columns column

 set @convert= 'select * from (select * from tblName) contributors
                            pivot (sum(points) for particulars in (' +@Columns + ')) as                               pivottbl'


--select @convert
execute (@convert)
 
Share this answer
 
Comments
bburhanbohra 30-Apr-13 6:46am    
Thank You so much...solution works...
PIVOT may help for your problem. Please try it.
 
Share this answer
 

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