日期:2014-05-17 浏览次数:20574 次
declare @sql nvarchar(max),
@stime datetime,
@etime datetime
select @stime=min(date),@etime=max(date)from tb
select @sql=isnull(@sql,'')+',max(case when date='''+convert(varchar(10),dateadd(day,number,@stime),23)+''' then num else 0 end)['+convert(varchar(10),dateadd(day,number,@stime),23)+']' from master..spt_values where type='p' and
convert(varchar(10),dateadd(day,number,@stime),23)<=convert(varchar(10),@etime,23)
exec('select [name]'+@sql+' from tb group by [name]')