Look for PIVOT in BOL - http://msdn.microsoft.com/en-us/library/ms177410(SQL.90).aspxdeclare @response table( UserId int,QuestionId int,ResponseValue varchar(32))insert into @response select 1, 1, '22' union all select 1, 2, 'Grey' union all select 2, 1, '33' union all select 2, 2, NULL declare @question table(QuestionId int,QuestionText varchar(32))insert into @question select 1, 'Whats your age?' union all select 2, 'Favorite color?'SELECT UserId, [Whats your age?],[Favorite color?]FROM ( SELECT R.userId, Q.QuestionText,R.ResponseValueFROM @question Q INNER JOIN @response RON q.QuestionId = r.QuestionId) MainPIVOT(MAX(ResponseValue)FOR QuestionText IN ([Whats your age?],[Favorite color?]))pVT
Mangal Pardeshihttp://mangalpardeshi.blogspot.com