日期:2014-05-17 浏览次数:20539 次
declare @sql nvarchar(max)
select @sql=isnull(@sql,'')+',max(case when CerName='''+CerName+''' then starttime else null end)['+CerName+'开始时间],max(case when CerName='''+CerName+''' then EndTime else null end)['+CerName+'结束时间]' from (select distinct CerName from tb)t
exec('select fid'+@sql+' from tb group by fid')