标签:io for ar sql ad har on rom
declare @sql varchar(8000)
begin
set @sql=‘‘ --初始化变量@sql
select @sql=@sql+‘,[‘+ convert(varchar(10),CreateDate,120)+‘]‘ from vwStationYield
where CreateDate > DATEADD(dd,-14,convert(varchar(10),getdate(),120)) group by convert(varchar(10),CreateDate,120)--变量多值赋值
set @sql=stuff(@sql,1,1,‘‘)--去掉首个‘,‘
print @sql
set @sql=‘select * from (select Product ,Yield, CreateDate from vwStationYield)as st
pivot --行转列
(max(Yield) for CreateDate in(‘+@sql+‘))as p‘
exec(@sql)
end
标签:io for ar sql ad har on rom
原文地址:http://www.cnblogs.com/fighting2014/p/3899537.html