Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
quesid questext optionid score performance
1 gdggf 1 10 Excellent
2 hghgkjhkjh 1 5 Excellent
3 ijk 2 12 Good
1 gdggf 3 3 Average
1 gdggf 4 4 Poor
1 gdggf 1 10 excellent




can i convert this table in to

quesid questext excelent good average poor
1 gdggf 20 0 3 4
2 hghgkjhkjh 5 0 0 0
3 ijk 0 12 0 0
Posted
Updated 8-Mar-13 20:13pm
v3

 
Share this answer
 
Check 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 Id,Qtxt,case when Excellent is null then 0 else Excellent end 'Excellent',case when Good is null then 0 else Good end 'Good',
case when Average is null then 0 else Average end 'Average',case when Poor is null then 0 else Poor end 'Poor'from @tab1e
 
Share this answer
 
Comments
gvprabu 9-Mar-13 2:29am    
Hi,
Don't do any home work for others...
give tips that is more than enough.
Davidduraisamy 9-Mar-13 2:30am    
Just helping others who are struggling..thats it...
Davidduraisamy 9-Mar-13 2:45am    
Ok..hereafter i will give only the suggestion.

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