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)
所有问题都会有一定程度的抽象和假设