Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hii

i am having a table v_feedabck in which i have follwins structure

ques_id qtxt opid score performance
1 gdggf 1 10 Excellent

2 6t7ik,ikik 2 12 Good
1 gdggf 3 3 Average
1 gdggf 4 4 Poor


i want this table like this


ques_id ques_txt excellent average good poor
1 gdggf 10 3 4
2 6t7ik,ikik 5 12
Posted
Comments
Davidduraisamy 9-Mar-13 1:10am    
Check the Result and let me know whether the problem solved or not

Hi,

Use this:

SQL
CREATE TABLE Aver(ques_id int,qtxt varchar(20),opid int,score int,performance varchar(30))

 insert into Aver values( 1,'gdggf',1,10,'Excellent'),( 2,'6t7ik,ikik',2,12,'Good'),(1,'gdggf',3,3,'Average'),(1,'gdggf',4,4,'Poor')


 select * from Aver
 declare @tab1e table(Id int,Qtxt varchar(20),Excellent int,Good int,Average int,Poor int)

 insert into @tab1e(ID)
 select distinct ques_id from Aver

update T set T.Qtxt=A.qtxt,T.Excellent=A.score from @tab1e T inner Join Aver A on A.ques_id=T.Id where A.performance='Excellent'
update T set T.Qtxt=A.qtxt,T.Good=A.score from @tab1e T inner Join Aver A on A.ques_id=T.Id where A.performance='Good'
update T set T.Qtxt=A.qtxt,T.Average=A.score from @tab1e T inner Join Aver A on A.ques_id=T.Id where A.performance='Average'
update T set T.Qtxt=A.qtxt,T.Poor=A.score from @tab1e T inner Join Aver A on A.ques_id=T.Id where A.performance='Poor'

select * from @tab1e
 
Share this answer
 
Comments
supriya931 9-Mar-13 2:11am    
SELECT ques_idI,[excelllent],[good],[average]
FROM v_feedback
PIVOT
(sum (score) FOR performance IN [excelllent],[good],[average] ) AS p
in this some where erroe near pivot element plz find any one
Davidduraisamy 9-Mar-13 2:14am    
is it working fine....
supriya931 9-Mar-13 2:39am    
no it give error nera pivot element.
and the above soluation working fine but the problem is that this query is not exist physically . and it is to large how to paste in coding
Davidduraisamy 9-Mar-13 2:42am    
you cant use pivot because there is no mean of using aggregate function in your query so you cant use pivot in this case,so my query is better option for this.
supriya931 9-Mar-13 3:35am    
ya it is working right but the problem is that you are making another table to make this i want to modify in same table that is i am using this syntax.
your table format change must no convert rows in to column
 
Share this answer
 
Comments
supriya931 9-Mar-13 0:55am    
1 gjhgjhg 10 30 4 like this
above i mentioned the column also

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