sql 数据列转行

1 declare @sql nvarchar(max);
2 select @sql = isnull(@sql + '],[' , '') + convert(varchar, FiledId) from resumeDetail group by FiledId order by filedId;
3 set @sql = '[' + @sql + ']';
4 set @sql = 'select resumeId,'+ @sql +' from (select FiledText,ResumeId,FiledId from resumeDetail) r pivot (max(FiledText) for FiledId in (' + @sql + ')) BM order by ResumeID';
5 exec sp_executesql @sql
posted @ 2011-04-29 13:46  小成时光  阅读(645)  评论(0编辑  收藏  举报