日期:2014-05-17 浏览次数:20590 次
Declare @sql varchar(max)
set @sql=STUFF((select ','+QUOTENAME(CONVERT(varchar(7),[time],120)) from [Table_4] b
where b.[time] between @time1 and @time2
group by CONVERT(varchar(7),[time],120) FOR XML PATH('')) ,1,1,'')
set @sql='select * from (SELECT CONVERT(varchar(7),[time],120) as saletime,[客户],[规格] FROM [master].[dbo].[Table_4]) t pivot (sum([QUAN])for t.saletime in ('+@sql+')) a ' exec(@sql)