Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with. 
    
        
            
                
                    
                        
                            
                                | Author | 
                                
                                 Topic  | 
                             
                            
                                    | 
                                         ssamnang 
                                        Starting Member 
                                         
                                        
                                        1 Post  | 
                                        
                                        
                                            
                                            
                                             Posted - 2014-02-20 : 05:46:17
                                            
  | 
                                             
                                            
                                            | Hi,I have a table to store questionnaire below:ID PKID   QuestionID     Scores1   1     01             02   1     02             13   1     03             04   2     01             05   2     02             06   2     03             0.....Is it possible to write a view to display result from above table in the following format if the given score is 0:PKID   QuestionID1      022      01, 02, 03   Sam | 
                                             
                                         
                                     | 
                             
       
                            
                       
                          
                            
                                    | 
                                     stepson 
                                    Aged Yak Warrior 
                                     
                                    
                                    545 Posts  | 
                                    
                                      
                                        
                                          
                                           
                                            Posted - 2014-02-20 : 06:22:28
                                          
  | 
                                         
                                        
                                          | [code];with aCTEAS (		select 1 ID, 1 PKID , '01' QuestionID,0 Scores union all		select 2, 1, '02' , 1 union all		select 3, 1, '03', 0 union all		select 4, 2, '01', 0 union all		select 5, 2, '02', 0 union all		select 6, 2, '03', 0)select  A.PKID,STUFF(B.QuestionID,1,1,'') as QuestionIDfrom 	(select PKID		from aCTE		Group by PKID ) A     outer apply	 (select ' ' + QuestionID + ','		from aCTE		where A.PKID=aCTE.PKID			AND aCTE.Scores=0		order by QuestionID	    for xml path('')	 ) B(QuestionID)	[/code]SsabinWeb MCP  | 
                                         
                                        
                                            | 
                                         
                                       
                                     | 
                                   
                            
                            
                                | 
                                    
                                      
                                     
                                    
                                 | 
                             
                         
                     | 
                 
             
         |   
     
     
            
              
	     |  
		
			
     
          
		 |