sqlserver 动态行转列

DECLARE @SQL VARCHAR(8000)
SET @SQL = 'select overcode '
SELECT @SQL = @SQL + ' , max(case header when ''' + header + ''' then 1 else 0 end) [' + header + ']'
FROM (SELECT DISTINCT header FROM overtime_detail) AS a
SET @SQL = @SQL + ' from overtime_detail group by overcode'
exec(@SQL)

posted @ 2013-11-04 19:57  Mark1997  阅读(363)  评论(0编辑  收藏  举报