should the rows become the column names?, in which case what are you actually selecting? in a 'normal' pivot query that would be your aggregate. some sample data / desired output would help illustrate it for us (including column names)below is a quick / rough example with dynamic sql. it is purely a starting point but should be enough to give you an idea of how to proceed...create table t (id int, prod varchar(20))insert into tvalues (1,'bike') ,(2,'egg') declare @sql varchar(1000)set @sql = 'select ' select @sql = @sql+ 'max(case when prod = ''' + prod + ''' then prod else null end),' from t set @sql = LEFT(@sql,LEN(@sql)-1)set @sql = @sql + ' from t'print @sqlexecute (@sql)
Em