pivot:
unpivot:
pivot实现动态列:
declare @depts nvarchar(1000),@sql nvarchar(4000)
select @depts=(select '['+DeptName+'],' from Edu_Department where IsBranch = 1 FOR XML PATH(''))
select @depts=LEFT(@depts,len(@depts)-1)
set @sql ='
select ......
pivot (max(info) for DeptName in('+@depts+')) t
) temp2'
exec(@sql)