Hi try this too, using dynamic pivot drop table #tempcreate table #temp ( col1 varchar(32), col2 varchar(32), orderdate datetime )insert into #temp select 'companya' ,'pizza' ,'3/4/2009'insert into #temp select 'companya' ,'donuts' ,'6/4/2009'insert into #temp select 'companya' ,'bagels' ,'7/4/2009'insert into #temp select 'companyb' ,'bagels' ,'7/4/2009'insert into #temp select 'companyb' ,'donuts' ,'5/4/2009'DECLARE @strcols VARCHAR(MAX), @values VARCHAR(MAX),@string VARCHAR(MAX)select @strcols = '' , @values = '' ,@string = '' SELECT @strcols = @strcols + ', MAX([' + col2 + ']) '+ col2, @values = @values + ', ['+ col2 + ']'from ( select distinct col2 from #temp ) tselect @string = 'select col1'+@strcols+' from #temp pivot(max(orderdate) for col2 in (' + stuff(@values,1,1,'') + '))p group by col1'exec(@string)