日期:2014-05-17 浏览次数:20594 次
declare @strsql varchar(1000)
set @strsql='select a.GroupName '
select @strsql=@strsql+',sum(case convert(char(10),inputtime,120) when '''+b.inputtime+''' then isnull(GroupCount,0) else 0 end)['+b.inputtime+']'
from (select distinct(convert(char(10),inputtime,120)) as inputtime from t2 ) b
set @strsql=@strsql+' from t1 as a,t2 as c where a.GroupId=c.GroupId Group by a.GroupName '
print(@strsql)
exec(@strsql)